1
我已將Spring從3.0.5升級到3.1.1,並偶然發現一個奇怪的問題。以下代碼在以前的版本中運行良好:Spring MVC中的響應實體3.1.1
@RequestMapping("/getPeople")
public Object getPeople()
{
HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.set("MyResponseHeader", "MyValue");
return new ResponseEntity("Hello World", responseHeaders, HttpStatus.OK);
}
但是,使用最新版本時出現404錯誤。要解決此我不得不提一下返回類型ResponseEntity的方法:
@RequestMapping("/getPeople")
public ResponseEntity getPeople()
{
HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.set("MyResponseHeader", "MyValue");
return new ResponseEntity("Hello World", responseHeaders, HttpStatus.OK);
}
這是一個可以接受的解決辦法還是我錯了,在這裏做什麼?
也許這將幫助:http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/mvc.html#mvc-ann-httpentity – vacuum 2012-04-08 20:24:48