gpt4 book ai didi

java - 仅从 Spring MVC 3 Controller 返回字符串消息

转载 作者:IT老高 更新时间:2023-10-28 11:38:50 25 4
gpt4 key购买 nike

谁能告诉我如何从 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com