我只想通过一个简单的servlet返回文本“ true”:
@RequestMapping(value = "/", method = RequestMethod.GET)
@ResponseBody
public Boolean isValid() {
return true;
}
结果:406 - The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.
。
为什么?我如何才能返回该简单值?如果将返回类型更改为,则没有任何区别String "true"
。
看来Spring MVC默认转换器无法转换Boolean
为text/plain
。仅当我尝试使用Accept: application/json
它时,该请求才有效。
我建议将返回类型更改为,String
因为无论如何这都是您要返回的内容。
@RequestMapping(value = "/", method = RequestMethod.GET)
@ResponseBody
public String isValid() {
return Boolean.TRUE.toString();
}
这样,没有Accept
标题的请求可以正常工作,但是Accept: text/plain
如果需要,您也可以添加。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句