【发布时间】:2017-04-09 05:10:09
【问题描述】:
我想知道当我在 Spring 中有一个带有属性的对象时,我是否可以使用像 Thymeleaf 这样的 Velocity 模板,比如说,(product.courseName),我想以这种方式将它发送到 HTML 页面
h1 th:text="${product.courseName}" HTML 示例课程名称 /h1
所以我可以直接显示它...
Thymeleaf 让我将 HTML 开发与 Spring Coding 隔离开来,但我在 Velocity 中找不到这么简单的方法。我可以在浏览器中显示带有“HTML 示例课程名称”的 HTML,并在 Velocity 执行时显示每个对象的真实课程名称(就像在 Thymeleaf 中一样)?
PD:如果有任何文档参考,我将不胜感激。
弹簧控制器
@RequestMapping("/product/{id}")
public String getProductById(@PathVariable Integer id, Model model){
model.addAttribute("product", productService.getProduct(id));
return "product";
}
PRODUCT.HTML
<div class="row">
<div class="col-md-12">
<h1 th:text="${product.courseName}">Course Name</h1>
</div>
</div>
谢谢
【问题讨论】: