[英]Spring controller not returning value when not using ResponseEntity
I have a controller like so, 我有一个像这样的控制器,
@RequestMapping(value = "/sample")
public ResponseEntity<> search() throws Exception{
return new ResponseEntity("Hello World",OK);
}
This works fine, but when I dont use ResponseEntity for returning the result but return the String instead, it does not work, 效果很好,但是当我不使用ResponseEntity返回结果而是返回String时,它不起作用,
@RequestMapping(value = "/sample")
public String search() throws Exception{
return "Hello Worls";
}
This does not work and I get a 404! 这不起作用,我得到了404! Any help greatly appreciated 任何帮助,不胜感激
Use ReponseBody
annotation: 使用ReponseBody
批注:
@RequestMapping(value = "/sample")
public @ResponseBody String search() throws Exception{
return "Hello Worls";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.