<div xmlns:th="http://www.w3.org/1999/xhtml" xmlns:sec="http://www.w3.org/1999/xhtml">
<span sec:authorize="hasAnyRole(${p})">
<button>Save</button>
</span>
</div>
我有此代码用于检查访问保存按钮的特权。
model.addattribute(" p",p);用P作为逗号分开的特权在控制器中添加。因此,如何检查用户具有给定的任何角色。
请考虑使用预处理功能。您可以按照以下方式进行:
<div xmlns:th="http://www.w3.org/1999/xhtml" xmlns:sec="http://www.w3.org/1999/xhtml">
<span sec:authorize="hasAnyRole(__${p}__)">
<button>Save</button>
</span>
</div>
请注意使用双重下划线的开始和结束字符,在这些字符中,百里叶在其他任何内容中都评估了此表达式。