目录
在进行了多次百度,还是无法解决thymeleaf的坑之后,我决定自己一个一个尝试,
ps: 很多人只讲语法, 艹,拿着语法,我发现还是无法完成我要的,必须得有实际例子,所以我猜想 那些只写 语法的人,肯定不是自己真正写过 thymeleaf ,或者在工程中用过,
配置非严格的语法
thymeleaf 有严格的语法限制,会极大程度限制你的发挥,所以先把这个模板的严格去掉
<!--非严格模式解析HTML5-->
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
导包,在application.yml中配置
spring.thymeleaf.cache=false
spring.thymeleaf.mode =LEGACYHTML5
spring.thymeleaf.content-type=text/html
html的坑
1。首先 js代码怎么写 必须 加上 th:inline
<script th:inline="javascript">
var loginids=[[${loginid}]];
var urls=[[${url}]];
</script>
2。 怎么 将 springBoot中的 model 存储的值取出来
<html xmlns:th="http://www.thymeleaf.org">
必须加上这个
html:<span th:text="${address}"></span>
js:var urls=[[${address}]];
- 怎么写url链接的按钮
SCH 就是 Controller类上的 reqMapping
Holiday就是 方法上的 Mapping
<a th:href="@{'/SCH/Holiday?code=1&state=2'}">返回</a>
如果你的url链接中有参数,是这个页面初始化传入的
<a th:href="@{/Money/backIndex(id=${loginid})}">返回</a>
- 怎么写 ajax请求
$.ajax({
type:'post',
dataType:'json',
url:'http:localhost:9090/por/PTC/goToWork', contentType:"application/json;charset=utf-8",
data: JSON.stringify(jsonsdata),
success:function(data){
if(data.code==0){
成功、、、、
}
}
})
5.怎么进行表达式的判断
<div th:if="${flag==0}"></div>
如果 flag==0 成立,那么div 里面的dom就会显示