如何使用Thymeleaf有条件地解析格式?

时间:2014-12-09 02:01:26

标签: thymeleaf

我是否可以通过Thymeleaf进行处理? Thymeleaf不喜欢open标签,但我只想为ROLE_A渲染它。

 <span sec:authorize="hasRole('ROLE_A')">      
      <div class="col-xs-10">
 </span>
 bunch of text not specific to ROLE_A
 <span sec:authorize="hasRole('ROLE_A')">
        custom text specific to ROLE_A
      </div>
 </span>

我尝试使用

 <sec:authorize="hasRole('ROLE_A')"> 

 <div sec:authorize="hasRole('ROLE_A')">. 

由于相同的开放标签问题,前者也无法运行,而后者正在混合封闭的div标签。

我有很多像这样的块,所以复制不同角色的部分并不是一个很好的解决方案。

1 个答案:

答案 0 :(得分:0)

不是你想要的风格。你需要关闭这些元素。

我的建议是考虑使用片段并根据需要加载所需的数据/

这样您就可以重用现有代码,从而使其更清晰,更小。

有关更多示例和方法,您可以查看Thymeleaf页面http://www.thymeleaf.org/doc/springsecurity.html

相关问题