Spring controller not returning value when not usi

2019-08-03 03:58发布

I have a controller like so,

@RequestMapping(value = "/sample")
    public ResponseEntity<> search() throws Exception{
        return new ResponseEntity("Hello World",OK);
    }

This works fine, but when I dont use ResponseEntity for returning the result but return the String instead, it does not work,

@RequestMapping(value = "/sample")
public String search() throws Exception{
    return "Hello Worls";
    }

This does not work and I get a 404! Any help greatly appreciated

1条回答
再贱就再见
2楼-- · 2019-08-03 04:17

Use ReponseBody annotation:

@RequestMapping(value = "/sample")
public @ResponseBody String search() throws Exception{
    return "Hello Worls";
}
查看更多
登录 后发表回答