我想知道以上哪一项更好/正确/最常用或什么。第一个,使用 @RequestMapping 中的值或其他使用路径。
@RequestMapping(value = { "/isbn/{isbnCode}" }, method = RequestMethod.GET)
public ResponseEntity<?> findByIsbnCode(@PathVariable String isbnCode) {
Book obj = service.findByIsbnCode(isbnCode);
return ResponseEntity.ok().body(obj);
}
// Request: http://localhost:8080/books/title?title=book_title
@RequestMapping(method = RequestMethod.GET, path = { "/title" })
public ResponseEntity<?> findByTitle(@RequestParam(value = "title") String title) {
Book obj = service.findByTitle(title);
return ResponseEntity.ok().body(obj);
}
// Request: http://localhost:8080/books/isbn/978-84-663-4612-2
两者都有效。就是想知道两者的区别。
提前致谢!