1.thymeleaf
引进:
<html xmlns:th="http://www.thymeleaf.org">
1.1 展示
<h1 th:text="${title}"></h1>
1.2 循环遍历
<table border="1px" width="600px"> <thead> <tr> <td>用户id</td> <td>用户姓名</td> <td>用户描述</td> </tr> </thead> <tbody> <tr th:each="user:${users}"> <td th:text="${user.uid}"></td> <td th:text="${user.userName}"></td> <td th:text="${user.desc}"></td> </tr> </tbody> </table>
1.3 下拉框
<select> <option th:each="user:${users}" th:value="${user.uid}" th:text="${user.userName}"></option> </select>
2.freemarker
2.1 导入相关依赖包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
2.2
2.3
2.3.1 取值
welcome 【${name}】to page
(注意:如果 传过来的name为null就会报错)
改为:welcome 【${name!}】to page 就不会报错
name有值则显示name的,没值则显示 ! 后面的
2.3.2 非空判断
<#if name?exists> xxxx </#if>
或者
<#if name??> xxxx </#if>
2.3.3 条件表达式
<#if sex=='boy'> 男 <#elseif sex=='girl'> 女 <#else> 保密 </#if>
2.3.4 循环
<table border="1px" width="600px"> <thead> <tr> <td>角色id</td> <td>角色名</td> <td>角色描述</td> </tr> </thead> <tbody> <#list roles as role> <tr> <td>${role.rid}</td> <td>${role.roleName}</td> <td>${role.desc}</td> </tr> </#list> </tbody> </table>
2.3.5 include
<#include 'foot.ftl'>
2.4
2.4.1
将项目名赋值给ctx1这个变量,这边的作用域在当前页面
<#assign ctx1> ${springMacroRequestContext.contextPath} </#assign>
2.4.2
将项目名赋值给ctx1这个变量,这边的作用域在整个项目
<#global ctx2> ${springMacroRequestContext.contextPath} </#global>
2.5
所有的springboot页面不能直接跳,需要经过后台。
2.6
引入js等文件