我有一个像这样的控制器,

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


效果很好,但是当我不使用ResponseEntity返回结果而是返回String时,它不起作用,

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


这不起作用,我得到了404!任何帮助,不胜感激

最佳答案

使用ReponseBody批注:

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

10-08 01:33