谁能告诉我如何从 Controller 返回字符串消息?
如果我只是从 Controller 方法返回一个字符串,那么 spring mvc 将其视为 jsp View 名称。
最佳答案
使用 @ResponseBody
在 Controller 中注释您的方法:
@RequestMapping(value="/controller", method=GET)
@ResponseBody
public String foo() {
return "Response!";
}
发件人:15.3.2.6 Mapping the response body with the @ResponseBody
annotation :
The
@ResponseBody
annotation [...] can be put on a method and indicates that the return type should be written straight to the HTTP response body (and not placed in a Model, or interpreted as a view name).
关于java - 仅从 Spring MVC 3 Controller 返回字符串消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7672858/