如何将整数附加到 url 脚本内联 thymeleaf?

How can I appen integer to url script inline thymeleaf?

我正在使用 Thymeleaf 和 Spring Boot。 我有一个 table 使用这些脚本创建:http://bootstrap-table.wenzhixin.net.cn/

然后我加了一个javascript:

<script th:inline="javascript">
    /*<![CDATA[*/
    $(function() {
        $("#list").on('click-row.bs.table',
        function(e, row, $element, field) {
            window.location = /*[[@{/url/}]]*/+row.id;
        });
    });
    /*]]>*/
</script>   

如您所见,我添加了 /*[[@{/url/}]]*/ 以生成正确的 url,但我必须将其与 ID 连接起来。

问题是它从不将 id 附加到 url.. 为什么? 我该如何解决?

您可以先将 Thymeleaf Java 对象放入某些 javascript 变量中,然后像通常在 javascript 中那样使用它。

var url = /*[[@{/url/}]]*/
window.location = url + row.id;

来自12.2 Script inlining (JavaScript and Dart) documentation

Thymeleaf will execute the expression and insert the result, but it will also remove all the code in the line after the inline expression itself (the part that is executed when displayed statically).