【发布时间】:2017-06-22 11:38:20
【问题描述】:
给定一个这样的控制器:
@RestController
@RequestMapping("/cars") {
public class CarController{
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<List<Cars>> getCars() { //logic }
@RequestMapping(method = RequestMethod.GET")
public ResponseEntity<List<Cars>> searchCar(@RequestParam("name") String name, @RequestParam("value") String value) { //logic}
}
如果 url 是这样的 localhost/cars 我想访问 getCars() 方法。
但如果网址是: localhost/cars?name=something&value=100 或
localhost/cars?name=something 或
localhost/cars?value=100
我想访问第二种方法。
这样可以吗?
【问题讨论】:
-
我不认为这是可能的,我建议只使用“/car”端点作为第二种方法。