目录
1、静态资源访问
Spring Boot 默认会挨个从META/resources > resources > static > public 里面找是否存在相应的资源,如果有则直接返回
1.1 默认配置
Spring Boot默认提供静态资源目录位置需置于classpath下,目录名需符合如下规则:
/static
/public
/resources
/META-INF/resources
举例:在src/main/resources/目录下创建public,在该位置创建public.html文件。启动程序后,尝试访问http://127.0.0.1:8888/study/public.html。
1.2 修改静态资源文件配置
增加一个image目录
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/image
直接访问增加的image目录的的图片:
2、请求转发和重定向
重定向redirect
@RequestMapping(path="/view/index_redirect")
public String getPage_redirect() {
//return “redirect:/page/view/index_forword”;
return “redirect:/public.html”;
}
转发forward
@RequestMapping(path="/view/index_forword")
public String getPage_forword() {
//return “forward:/page/view/index_redirect”;
return “forward:/public.html”;
}
3、渲染Web页面
3.1 整合thymeleaf模板引擎
3.1.1 Thymeleaf 常用的表达式、标签和函数
1.常用表达式