Return only string message from Spring MVC 3 Controller

后端 未结 7 691
死守一世寂寞
死守一世寂寞 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:06

    With Spring 4, if your Controller is annotated with @RestController instead of @Controller, you don't need the @ResponseBody annotation.

    The code would be

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

    You can find the Javadoc for @RestController here

提交回复
热议问题