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