【Thymeleaf】使用学习
【Thymeleaf】使用学习
javacc、antlr、jflex
使用 attoparser 解析 https://www.attoparser.org/
===================================================================
1、spring boot 整合 Thymeleaf
2、spring security 使用
3、文本语法,没有 html 标签
4、标签使用
===================================================================
1、spring boot 整合 Thymeleaf
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.5.3</version> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.1</version> </dependency>
配置
server: port: 8088 spring: devtools: restart: enabled: true mvc: # 静态资源的请求方式 static-path-pattern: /static/** resources: # # 静态资源的配置位置 static-locations: classpath:/static/ # 模板 thymeleaf: # 开发不缓存false,生产环境缓存true cache: false # 数据源 datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://mysql.dev:3306/gh?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&autoReConnect=true username: root password: 123456 # hikari连接池的参数 相关设置 hikari: # 生效超时 validationTimeout: 3000 # 定义获取连接的超时时间。最小250ms,默认30s connectionTimeout: 60000 # 定义连接空闲时间。最小10s,默认10m idleTimeout: 60000 # 定义最小的空闲连接数。推荐不设置。或与最大连接数一致;保持固定的连接数目 minimumIdle: 10 # 定义最大的连接数。默认10 maximumPoolSize: 10 # 定义连接的最大生命周期。推荐设置该属性。最小30s,默认30m maxLifeTime: 60000 # 从连接池获取到连接后,进行检查的查询语句。推荐设置该属性。默认值为none connectionTestQuery: select 1 # redis 配置 redis: # 数据库 database: 0 # 地址 host: redis.dev # 端口,默认为6379 port: 6379 # 密码 # password: 123456 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 4 # 连接池中的最大空闲连接 max-idle: 10 # 连接池的最大数据库连接数 max-active: 10 # 连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # MyBatis配置 mybatis: # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapper-locations: classpath*:mapper/*Mapper.xml
2、spring security 使用
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.thymeleaf.extras</groupId> <artifactId>thymeleaf-extras-springsecurity5</artifactId> </dependency>
页面引入
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:sc="http://www.thymeleaf.org/extras/spring-security">
${#authentication.principal.menus}
3、文本语法,没有 html 标签
嵌入表达式
[[...]] 相当于 th:text 会转义 HTML-escaped
[(...)] 相当于 th:utext 不会转义
比如 msg 的值是 “<b>你好</b>”
th:text 会执行 html 转义 HTML-escaped,页面结果和值一样:<b>你好</b>
th:utext 不会转义,页面结果是标签执行后的值:你好
也就是说 th:text 原样显示,而 th:utext会把标签解析成html
记录条数:[[${result.total}]]
记录条数:[(${result.total})]
4、标签使用
文本:th:text 或 th:utext
比如 msg 的值是 “<b>你好</b>”
th:text 会执行 html 转义 HTML-escaped,页面结果和值一样:<b>你好</b>
th:utext 不会转义,页面结果是标签执行后的值:你好
也就是说 th:text 原样显示,而 th:utext会把标签解析成html
th:text="${msg}"
th:utext="${msg}"
循环:th:each
<li th:class="${page} == ${menu.permission} ? 'h' : ''" th:each="menu : ${#authentication.principal.menus}" th:attr="request=${menu.request}" th:text="${menu.name}"></li>
日期格式化
<span th:text="${#dates.format(row.expireDate, 'yyyy-MM-dd')}"></span>
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性