spring boot模板

时间:2019-02-19
本文章向大家介绍spring boot模板,主要包括spring boot模板使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

thymeleaf模板——它就是html页面
相关pom依赖

org.springframework.boot
spring-boot-starter-thymeleaf

Spring Boot官方文档建议在开发时将缓存关闭,那就在application.properties文件中加入下面这行
spring.thymeleaf.cache=false
正式环境还是要将缓存开启的

th:value`<html xmlns:th="http://www.thymeleaf.org">
    <tr th:each="user : ${users}">
    <td th:text="${user.uid}"></td>
    <td th:text="${user.userName}"></td>
    <td th:text="${user.desc}"></td>
</tr> 
<select>
    <option th:each="user :${users}" th:value="${user.uid}" th:text="${user.username}"></option>
</select>

freemarker模板
org.springframework.boot
spring-boot-starter-freemarker
`
application.yml文件的默认配置

spring:
thymeleaf:
cache: false
freemarker:
# 设置模板后缀名
suffix: .ftl
# 设置文档类型
content-type: text/html
# 设置页面编码格式
charset: UTF-8
# 设置页面缓存
cache: false
# 设置ftl文件路径,默认是/templates,为演示效果添加role
template-loader-path: classpath:/templates/role
mvc:
static-path-pattern: /static/**

list.ftl

角色列表 <#include 'commen.ftl'>

取值

wecome [${name!'未知'}] to page

非空判断

<#if name?exists>
hhhhhhhhhhhh哈哈哈哈哈
</#if>

条件表达式

<#if sex=='boy'> 男孩 <#elseif sex=='girl'> 女孩 <#else > 保密 <#list users as user>
ID 姓名 密码
${user.uid} ${user.username} ${user.password}

变量的设置(局部,全局的)

<#assign ctxl> ${springMacroRequestContext.contextPath}

include

<#include 'foot.ftl'>

login.ftl
版权信息
登陆1//进不去

登陆