【发布时间】:2020-02-19 12:31:25
【问题描述】:
我有一个控制器:
@RestController
@RequestMapping(value = UserRestController.REST_URL, produces =
MediaType.APPLICATION_JSON_VALUE)
public class UserRestController {
static final String REST_URL = "/customers";
@GetMapping
public List<User> getAll() {
return service.getAll();
}
}
它成功处理了这样的请求,如:
GET: /customers/
而我想通过一些参数来获取用户。例如邮箱:
GET: /customers?email=someemail@gmail.
我试过了:
@GetMapping("/")
public User getByEmail(@RequestParam(value = "email") String email) {
return super.getByEmail(email);
}
预计我会收到一个异常,因为“/”已经映射到 getAll-class 上。 有没有办法解决这个问题?
【问题讨论】:
-
试试这个
@GetMapping("/email") public User getByEmail(@RequestParam(value = "email") String email) { return super.getByEmail(email); } -
这种方式可行,但它映射到 /customers/email?email=someemail@gmail。我需要 /customers?email=someemail@gmail.
标签: java spring rest spring-restcontroller http-request-parameters