springboot的web相关(1)

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

1.加载静态资源

1.所有 /webjars/** ,都去 classpath:/META-INF/resources/webjars/ 找资源;
2)、”/**” 访问当前项目的任何资源,都去(静态资源的文件夹)找映射
localhost:8080/abc === 去静态资源文件夹里面找abc
3)、欢迎页; 静态资源文件夹下的所有index.html页面;被”/**”映射;
localhost:8080/ 找index页面
4)、所有的 **/favicon.ico 都是在静态资源文件下找;
“classpath:/META‐INF/resources/”,
“classpath:/resources/”,
“classpath:/static/”,
“classpath:/public/”
“/”:当前项目的根路径

2.模板引擎

目前各种的模板引擎:JSP、Velocity、Freemarker、Thymeleaf

SpringBoot推荐的Thymeleaf;
语法更简单,功能更强大;
1、引入thymeleaf;

<dependency>         
<groupId>org.springframework.boot</groupId>             
<artifactId>spring‐boot‐starter‐thymeleaf</artifactId>             
           2.1.6   
</dependency>         
切换thymeleaf版本
<properties>
<thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>         
<!‐‐ 布局功能的支持程序  thymeleaf3主程序  layout2以上版本 ‐‐>         
<!‐‐ thymeleaf2   layout1‐‐>         
<thymeleaf‐layout‐dialect.version>2.2.2</thymeleaf‐layout‐dialect.version>         
  </properties>

2、Thymeleaf使用
只要我们把HTML页面放在classpath:/templates/,thymeleaf就能自动渲染;
使用:
1、导入thymeleaf的名称空间

2、使用thymeleaf语法;

3、语法规则
1)、th:text;改变当前元素里面的文本内容;
th:任意html属性;来替换原生属性的值

3、SpringMVC自动配置

  1. Spring MVC auto-configuration
    Spring Boot 自动配置好了SpringMVC
    以下是SpringBoot对SpringMVC的默认配置:(WebMvcAutoConfiguration)

4.国际化

1)、编写国际化配置文件;
2)、使用ResourceBundleMessageSource管理国际化资源文件
3)、在页面使用fmt:message取出国际化内容

步骤:
1)、编写国际化配置文件,抽取页面需要显示的国际化消息

猜你喜欢

转载自blog.csdn.net/sinat_27912569/article/details/80243558
今日推荐