thymeleaf获取数据
thymeleaf获取数据
·
一、thymeleaf 获取session:
${session.username}
其中username 为: session内的属性名
二、thymeleaf获取request参数:
${param.question}
//question是前端传入的参数
三、Thymeleaf 模板中获取 spring Security 登录用户:
1、添加依赖
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
2、html头部添加:
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
3、html中获取用户名:
<span sec:authentication="name"></span>
四、thymeleaf标签获取后台数据(Model)
1、后台Controller控制器
model.addAttribute("a",a);//a是对象,里面包含age
model.addAttribute("b", b);
model.addAttribute("c", b);
model.addAttribute("d", d);
model.addAttribute("e", e);
2、前端页面
<span th:text="${a.age}"></span>
//a是对象,age是a的成员
五、另外:JS获取Model中的数据
<script th:inline="javascript">
var a = [[${workDetail}]];
var b = [[${workDetail.id}]];
var c = [[${workDetail.workNumber}]];
var d = [[${workDetail.issueNumber}]];
var e = [[${workDetail.workName}]];
var f = [[${workDetail.fence.lonLats}]];
</script>
//即是:[[${Key名}]]
更多推荐
已为社区贡献14条内容
所有评论(0)