像 Thymeleaf 这样的速度解决方案

Velocity solution like Thymeleaf

我想知道当我在 Spring 中有一个具有属性的对象时,我是否可以使用像 Thymeleaf 这样的 Velocity 模板,比方说,(product.courseName),我想将它发送到一个HTML 这样翻页

h1 th:text="${product.courseName}" HTML Example Course Name /h1

所以我可以直接显示...

Thymeleaf 让我将 HTML 开发与 Spring 编码 隔离开来,但我在 Velocity 中找不到如此简单的方法。当 Velocity 执行时(就像在 Thymeleaf 中一样),我可以在浏览器中显示 HTML 和 "HTML Example Course Name" 以及每个对象的真实课程名称吗?

PD:如果有任何文档参考,我将不胜感激。

SPRING 控制器

@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>

谢谢

是的,但不完全是你在做。如果您查看参考文档的 properties 部分,它解释了如何操作:

Properties

The second flavor of VTL references are properties, and properties have a distinctive format. The shorthand notation consists of a leading $ character followed a VTL Identifier, followed by a dot character (".") and another VTL Identifier. These are examples of valid property references in the VTL:

$customer.Address
$purchase.Total

还有解释,如果你使用它,它会像 thymeleaf 一样调用 属性 的 getter。

$customer.Address. It can have two meanings. It can mean, Look in the hashtable identified as customer and return the value associated with the key Address. But $customer.Address can also be referring to a method (references that refer to methods will be discussed in the next section);

$customer.Address could be an abbreviated way of writing $customer.getAddress()

........

已编辑

所以在简历中,不要使用 thymeleaf 标签,例如 th:text

<h1>$product.courseName</h1>