java - Thymeleaf 中的可选参数?

标签 java thymeleaf

是否可以在 Thymeleaf 中使用可选参数创建片段?

<div th:fragment="personfragment(name, age, optionalargs...)">

所以我可以用以下任一方式调用它:

<div th:replace="personfragment('john', '28', 'arg1')" />
<div th:replace="personfragment('john', '28', 'arg1', 'arg2', 'arg3')" />

不是重复的,因为我事先不知道参数的数量。这就是可选参数的用途:不必设置数字或参数!

如果有人知道如何像数组参数一样传递参数,我也会很高兴?

最佳答案

使用作为对象的单个参数。

然后,您可以检查片段内的对象并提取相关属性(如果存在)。

关于java - Thymeleaf 中的可选参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57889062/

相关文章:

Java 泛型工厂模式

java - 从java中查找sql​​和mysql和pgsql中最后一个查询的执行时间

java - 如何在BottomBar布局android中添加中间按钮

spring-security - spring security thymeleaf LockedException 自定义消息

java - Spring 在上传到服务器时损坏 Excel(xlsx, xls) 文件 (org.apache.poi)

if-statement - ThymeLeaf : how to do it in plain text? 中的条件文本

java - 我研究 thymeleaf ,但我不知道这是什么意思 :field from this <select>

java - 无法为应用引擎项目创建谷歌凭据

java - Jmeter中单击生成多个请求

spring - thymeleaf :each two iterate two listings