本地部署到服务器上的资源路径问题
服务器端的源代码的静态资源目录层级
当使用Thymeleaf时,在templates的目录下为返回的html页面,下面以两个例子解释当将代码部署到tomcat时访问资源的路径配置问题
例子一 index.html(在templates的根目录下)
调用controller的接口
http://localhost:8080/community/index
@GetMapping("/index")
public String getIndexPage(Model model, Page page){
//方法调用前,SpringMVC会自动实例化Model和Page,并将Page注入Model,
// 所以,在thymeleaf中可以直接访问Page对象中的数据,不需要使用model.addAttribute()方法进行数据模型的添加
page.setRows(discussPostService.findDiscussPostRows(0));//查询帖子的总数
page.setPath("/index");