Thymleaf javascript变量组合

时间:2015-12-11 10:31:28

标签: javascript spring-mvc spring-boot thymeleaf template-engine

我在春季靴子项目中使用百里香。它运作良好。现在我需要在JavaScript中将一个url呈现为​​字符串,并且需要与一个JavaScript变量连接。我试过以下代码。

location.href = /*[[@{/signage/save}]]*/ '' + res.id

但生成的输出是

location.href='/signage/save';

我想要的是

location.href = '/signage/save' + res.id;

我怎样才能实现它?

2 个答案:

答案 0 :(得分:2)

如果使用特殊注释语法/*[+...+]*/动态提供页面,您可以告诉Thymeleaf取消注释某些代码。在这个注释块中,你可以放置表达式,它们将与整个块一起评估。

/*[+ location.href = [[@{/signage/save}]] + res.id +]*/

将呈现为

location.href = '/signage/save' + res.id

答案 1 :(得分:1)

尝试了几个方法后得到了解决方案,不完全是我需要的,但它对我有用。我只是用括号( public class PerformanceListItem { private String pSid; private String pStaffName; private String pDesignation; private String pPerformance; private String pList; public PerformanceListItem(){ } public PerformanceListItem(String pList){ this.pList = pList; } public String getpSid(){ return pSid; } public void setpSid(String pSid){ this.pSid = pSid; } public String getpStaffName(){ return pStaffName; } public void setpStaffName(String pStaffName){ this.pStaffName = pStaffName; } public String getpDesignation(){ return pDesignation; } public void setpDesignation(String pDesignation){ this.pDesignation = pDesignation; } public String getpPerformance(){ return pPerformance; } public void setpPerformance(String pPerformance){ this.pPerformance = pPerformance; } }

包裹它
(.....)

并生成输出

location.href = (/*[[@{/signage/save}]]*/ '') + res.id