版权声明:本文为博主原创文章,未经博主允许不得转载。 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下才可以正常运行。