2.创建.html文件org.springframework.boot spring-boot-starter-thymeleaf
在中添加xmlns:th=“http://www.thymeleaf.org”,如下
3.语法
th:text="${变量}" 改变文本的值
变量通过controller中model.addAttribute(“msg”,“atguigu”);发送
哈哈
th:href=“${变量}”; //跳转到该页面
th:href=“@{变量}”; //在默认途径后面加上此 路径
路径中添加参数
书名: [[${Product?.name}]]
售价:¥[[${Product?.price}]]
去百度 去百度
th:src
获取request中的值**:[[${变量}]]
如 order为Controller中request.setAttribute(“order”,order)中的值
[[${order.id}]] [[${order.receiverName }]] [[${order.ordertime}]] [[${order.paystate==0?"未支付":"已支付"}]]
th:value
th:value="${session?.user?.username}"
th:each 循环
| [[${vs.count}]] | [[${entry.key.name }]] | [[${entry.key.price }]] | [[${entry.key.category}]] | [[${entry.value}]] | [[${entry.key.price*entry.value}]] |
th:if 判断
th:style设置背景
th:
th:onclick
传递参数
如:传递三个参数
前提是:
onclick="javascript:return cart_del()">X
获取session中的值:[[${session.变量}]]
user为Controller中session.setAttribute(“user”,user)中的值;
如果session中的变量不存在,则会报错,可使用[[${session?.变量}]]进行判断,如果变量不存在,则不显示
你好,[[${session?.user?.username}]]!欢迎您来到网上书城结算中心
th:insert 引入其他html
client/head为其他静态资源的相对路径
#divhead表示client/head中id为divhead的部分
注意:如果导入的client/head::#divhead中引入了其他的css或者js文件需要将css/js等静态资源包含在div中才可生效



