zoukankan      html  css  js  c++  java
  • spring boot-9.对springMVC的支持

    1.thymeleaf

    spring boot 推荐的模板引擎是thymeleaf。spring boot 的自动配置已经默认配置好了themleaf,只要导入themleaf的Starter就可以了。

    <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-thymeleaf</artifactId>

    </dependency>

    为了使用themleaf的高级特性,建议将themleaf版本切换至3.0以上

    <properties>
            <thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
            <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
    </properties>

    themleaf 可以用th:开头的所有标签去替换原生html的相应标签,主要的语法有以下几个点:

    (1)${...} 取变量的值,类似于OGNL

    (2)#{...}:获取国际化内容

    (3)@{...}:定义URL

    (4)~{...}:片段引用表达式

    (5)*{...}:选择变量表达式,功能和${}类似

    themleaf 同时支持字符串操作,数学计算,比较,条件判断,还内置了很多工具方法,如可以进行日期格式化的方法${#dates.format(date)},具体可查看themleaf 官方网站,https://www.thymeleaf.org

    2.SpringMVC自动配置

    (1)自动配置了视图解析器

    (2)自动配置了静态资源文件夹路径及webjars路径

    (3)自动配置了首页

    (4)自动配置了ico图标

    (5)自动注册了 of Converter, GenericConverter(转换器), Formatter(格式化器)

    可以在全局配置文件的spring.mvc 的配置中修改自动配置。

    3.扩展spring MVC 配置

    扩展spring MVC 功能需要编写一个WebMvcConfigurerAdapter类型的配置类(@Configuration),在配置类中实现相应的配置,如果容器中已经存在相应的配置,则自动配置和扩展配置同时生效。

  • 相关阅读:
    【luogu P1307 数字反转】 题解
    【luogu P1111 公路修建】 题解
    字符串与正则运算
    Java 正则表达式的总结和一些小例子
    js -history.back(-1)和history.go(-1) 区别
    js
    html _ 提取html片段内的纯文本
    vue-x action 的相互调用
    java通过过滤器 设置跨域允许
    git-搭建企业git服务器
  • 原文地址:https://www.cnblogs.com/li-zhi-long/p/9493442.html
Copyright © 2011-2022 走看看