@Controller和@RestController注解区别

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37890535/article/details/82563287

@Controller处理Http请求和@RestController处理Http请求

@Controller
public class HelloController {
    @RequestMapping("/index")
    public String getIndex() {
        return "view/index";
}

@RestController
public class HelloController {
    @RequestMapping("/index")
    public String getIndex() {
        return "view/index";
}

这里@RestController中的getIndex()方法返回的是字符串view/index,而@Controller中的getIndex()方法返回的是一个路径,表明index.hmtl所在的位置。该路径如下图所示:页面文件路径示意图
注意路径要在工程的templates下才可以正常运行。

猜你喜欢

转载自blog.csdn.net/m0_37890535/article/details/82563287