Return only string message from Spring MVC 3 Controller

后端 未结 7 637
死守一世寂寞
死守一世寂寞 2020-11-28 04:50

Can any one tell me how I can return string message from controller?

If i just return a string from a controller method then spring mvc treating it as a jsp view nam

相关标签:
7条回答
  • 2020-11-28 05:23

    Annotate your method in controller with @ResponseBody:

    @RequestMapping(value="/controller", method=GET)
    @ResponseBody
    public String foo() {
        return "Response!";
    }
    

    From: 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).

    0 讨论(0)
提交回复
热议问题