【发布时间】:2016-02-29 14:17:50
【问题描述】:
我只想通过一个简单的 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",则没有区别。
【问题讨论】:
-
您希望得到什么响应?一串
true? -
没错。我只想返回“true”。
-
请求中似乎有接受标头。你能找出它们是什么吗?也许您必须为响应提供一个 mime 类型(例如 text/plain 或 application/xml ...)
-
我想你正在寻找String#valueOf。你可以写成
return String.valueOf(true);。
标签: java spring rest spring-restcontroller spring-rest