我有一個彈簧啓動應用程序,它有一個彈簧MVC控制器。我正在嘗試使用Accept標頭對我的其餘api進行版本化。彈簧MVC控制器版本
以下是我的控制器看起來像
RestController
@RequestMapping(value = "/private/")
public class AppleController {
private final AppleService appleService;
public AppleController(AppleService appleService) {
this.appleService = appleService;
}
@GetMapping(value = "apples/{id}", produces = "application/json; v=1.0",
headers = "Accept=application/json; v=1.0")
public ResponseEntity getByappleId(@PathVariable("id") Long appleId) {
System.out.println("version1");
GetByappleIdResponse response = appleService.findByappleId(appleId);
return new ResponseEntity<>(response, HttpStatus.OK);
}
@GetMapping(value = "apples/{id}", produces = "application/json; v=2.0",
headers = "Accept=application/json; v=2.0")
public ResponseEntity getByappleId2(@PathVariable("id") Long appleId) {
System.out.println("version2");
GetByappleIdResponse response = appleService.findByappleId2(appleId);
return new ResponseEntity<>(response, HttpStatus.OK);
}
的調用總是API時,我傳遞的Accept頭的版本無論「getByappleId」方法被調用,則返回1個響應因此,只有版本。
我的控制器有什麼問題嗎?
好像頭不使用彈簧在接受接受-PARAMS 。 –
可能的重複http://stackoverflow.com/questions/34425316/spring-requestmapping-header-with-equals – heenenee
脫離主題不要使用system.out儘可能使用記錄器 –