thymethymeleaf取model值_Thymeleaf取出model中的数据
后端在controller中⽤model存⼊数据
这⾥是将⼀个Blog的类存⼊键为"blog"的键值对中
@GetMapping("/blog/{id}")
public String blog(@PathVariable Long id, Model model) {
model.addAttribute("blog", AndConvert(id));
return "blog";
}
渲染到前端时取出model中的数据
class="ui avatar image">
th:text="${#dates.format(blog.updateTime, 'yyyy-MM-dd')}">2020-08-29
2342
JavaScript取值
var url = /*[[@{/blog/{id}(id=${blog.id})}]]*/"";
其中注释部分在静态页⾯中是注释,但是使⽤Thymeleaf渲染时就会被当做正常的代码,⽽后⾯的原来属于js的字符串部分则会被此“注释”替代掉。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。