[英]How to substring variable and concatenate it with url in Thymeleaf
我想要 substring 一个变量,它是我的 JPA class id 字段,然后将它添加到 Thymeleaf 中的 URL。
我的 URL 就像
/Myapplication/sortddoc/value=__${entity.id}__
所以我需要做类似的事情
${entity.id}.substr(0, 8)
在将其连接到 URL 之前。
我试图在包含 substring 变量的实体 class 中创建一个新的 Transient 字段,但它不起作用,因为它似乎需要我无法提供的数据库字段。
任何人都可以帮助我吗?
您应该使用 Thymeleaf 的 标准 URL syntax来执行此操作,而不是连接字符串变量或使用预处理(这两者都不需要)。
<a th:with="${value=#strings.substring(entity.id,0,8)}"
th:href="@{/Myapplication/sortddoc/(value=${value})}"></a>
要么
<a th:href="@{/Myapplication/sortddoc/(value=${#strings.substring(entity.id,0,8)})}"></a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.