spring boot 简单返回字符串hello的TestController,404 Not Found

错误代码如下:

@Controller
public class TestController {
    @RequestMapping("/test")
    public String test(){
        return "hello";
    }
}

正确代码如下:

@Controller
public class TestController {
    @RequestMapping("/test")
    @ResponseBody //使用@Controller时,由于有@ResponseBody注解的存在,这个字符串将不会被解析为页面路径或视图名,而是直接作为HTTP响应的内容
    public String test(){
        return "hello";
    }
}