mirror of
https://gitee.com/dromara/sa-token.git
synced 2024-11-30 02:48:10 +08:00
新增标签方言命名空间,增强 ide 代码提示
This commit is contained in:
parent
5a5ba1d634
commit
03f28da988
@ -10,7 +10,8 @@ public class SaTokenThymeleafDemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SaTokenThymeleafDemoApplication.class, args);
|
||||
System.out.println("\n启动成功:sa-token配置如下:" + SaManager.getConfig());
|
||||
System.out.println("\n启动成功,Sa-Token 配置如下:" + SaManager.getConfig());
|
||||
System.out.println("\n测试访问:http://localhost:8081/");
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
<html lang="zh" xmlns:sa="http://www.thymeleaf.org/extras/sa-token">
|
||||
<head>
|
||||
<title>Sa-Token 集成 Thymeleaf 标签方言</title>
|
||||
<meta charset="utf-8">
|
||||
@ -9,28 +9,28 @@
|
||||
<div class="view-box" style="padding: 30px;">
|
||||
<h2>Sa-Token 集成 Thymeleaf 标签方言 —— 测试页面</h2>
|
||||
<p>
|
||||
<a href="login" target="_blank">登录</a>
|
||||
<a href="login" target="_blank">登录</a>
|
||||
<a href="logout" target="_blank">注销</a>
|
||||
</p>
|
||||
|
||||
|
||||
<p>登录之后才能显示:<span sa:login>value</span></p>
|
||||
<p>不登录才能显示:<span sa:notLogin>value</span></p>
|
||||
|
||||
|
||||
<p>具有角色 admin 才能显示:<span sa:hasRole="admin">value</span></p>
|
||||
<p>同时具备多个角色才能显示:<span sa:hasRoleAnd="admin, ceo, cto">value</span></p>
|
||||
<p>只要具有其中一个角色就能显示:<span sa:hasRoleOr="admin, ceo, cto">value</span></p>
|
||||
<p>不具有角色 admin 才能显示:<span sa:lackRole="admin">value</span></p>
|
||||
|
||||
<p>不具有角色 admin 才能显示:<span sa:notRole="admin">value</span></p>
|
||||
|
||||
<p>具有权限 user-add 才能显示:<span sa:hasPermission="user-add">value</span></p>
|
||||
<p>同时具备多个权限才能显示:<span sa:hasPermissionAnd="user-add, user-delete, user-get">value</span></p>
|
||||
<p>只要具有其中一个权限就能显示:<span sa:hasPermissionOr="user-add, user-delete, user-get">value</span></p>
|
||||
<p>不具有权限 user-add 才能显示:<span sa:lackPermission="user-add">value</span></p>
|
||||
|
||||
<p>不具有权限 user-add 才能显示:<span sa:notPermission="user-add">value</span></p>
|
||||
|
||||
<p th:if="${stp.isLogin()}">
|
||||
从SaSession中取值:
|
||||
<span th:text="${stp.getSession().get('name', '')}"></span>
|
||||
</p>
|
||||
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -72,7 +72,7 @@ public class SaTokenConfigure {
|
||||
</p>
|
||||
<p>
|
||||
不具有角色 admin 才能显示:
|
||||
<span sa:lackRole="admin">value</span>
|
||||
<span sa:notRole="admin">value</span>
|
||||
</p>
|
||||
```
|
||||
|
||||
@ -92,7 +92,7 @@ public class SaTokenConfigure {
|
||||
</p>
|
||||
<p>
|
||||
不具有权限 user-add 才能显示:
|
||||
<span sa:lackPermission="user-add">value</span>
|
||||
<span sa:notPermission="user-add">value</span>
|
||||
</p>
|
||||
```
|
||||
|
||||
|
@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~ =============================================================================
|
||||
~
|
||||
~ Copyright (c) 2011-2018, The THYMELEAF team (http://www.thymeleaf.org)
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
~
|
||||
~ =============================================================================
|
||||
-->
|
||||
|
||||
<dialect
|
||||
xmlns="http://www.thymeleaf.org/extras/dialect"
|
||||
prefix="sa"
|
||||
namespace-uri="http://www.thymeleaf.org/extras/sa-token"
|
||||
class="cn.dev33.satoken.thymeleaf.dialect.SaTokenDialect">
|
||||
|
||||
<!-- 登录判断 -->
|
||||
<attribute-processor name="login">
|
||||
<documentation> <![CDATA[ 登录之后才能显示元素 ]]> </documentation>
|
||||
</attribute-processor>
|
||||
<attribute-processor name="notLogin">
|
||||
<documentation> <![CDATA[ 不登录才能显示元素 ]]> </documentation>
|
||||
</attribute-processor>
|
||||
|
||||
<!-- 角色判断 -->
|
||||
<attribute-processor name="hasRole">
|
||||
<documentation> <![CDATA[ 具有指定角色才能显示元素 ]]> </documentation>
|
||||
</attribute-processor>
|
||||
<attribute-processor name="hasRoleAnd">
|
||||
<documentation> <![CDATA[ 同时具备多个角色才能显示元素 ]]> </documentation>
|
||||
</attribute-processor>
|
||||
<attribute-processor name="hasRoleOr">
|
||||
<documentation> <![CDATA[ 只要具有其中一个角色就能显示元素 ]]> </documentation>
|
||||
</attribute-processor>
|
||||
<attribute-processor name="notRole">
|
||||
<documentation> <![CDATA[ 不具有指定角色才能显示元素 ]]> </documentation>
|
||||
</attribute-processor>
|
||||
<attribute-processor name="lackRole">
|
||||
<documentation> <![CDATA[ 不具有指定角色才能显示元素(未来版本可能废弃,建议更换为 notRole) ]]> </documentation>
|
||||
</attribute-processor>
|
||||
|
||||
<!-- 权限判断 -->
|
||||
<attribute-processor name="hasPermission">
|
||||
<documentation> <![CDATA[ 具有指定权限才能显示元素 ]]> </documentation>
|
||||
</attribute-processor>
|
||||
<attribute-processor name="hasPermissionAnd">
|
||||
<documentation> <![CDATA[ 同时具备多个权限才能显示元素 ]]> </documentation>
|
||||
</attribute-processor>
|
||||
<attribute-processor name="hasPermissionOr">
|
||||
<documentation> <![CDATA[ 只要具有其中一个权限就能显示元素 ]]> </documentation>
|
||||
</attribute-processor>
|
||||
<attribute-processor name="notPermission">
|
||||
<documentation> <![CDATA[ 不具有指定权限才能显示元素 ]]> </documentation>
|
||||
</attribute-processor>
|
||||
<attribute-processor name="lackPermission">
|
||||
<documentation> <![CDATA[ 不具有指定权限才能显示元素(未来版本可能废弃,建议更换为 notPermission) ]]> </documentation>
|
||||
</attribute-processor>
|
||||
|
||||
</dialect>
|
@ -72,14 +72,16 @@ public class SaTokenDialect extends AbstractProcessorDialect {
|
||||
|
||||
// 角色判断
|
||||
new SaTokenTagProcessor(prefix, "hasRole", value -> stpLogic.hasRole(value)),
|
||||
new SaTokenTagProcessor(prefix, "hasRoleOr", value -> stpLogic.hasRoleOr(toArray(value))),
|
||||
new SaTokenTagProcessor(prefix, "hasRoleAnd", value -> stpLogic.hasRoleAnd(toArray(value))),
|
||||
new SaTokenTagProcessor(prefix, "hasRoleOr", value -> stpLogic.hasRoleOr(toArray(value))),
|
||||
new SaTokenTagProcessor(prefix, "notRole", value -> ! stpLogic.hasRole(value)),
|
||||
new SaTokenTagProcessor(prefix, "lackRole", value -> ! stpLogic.hasRole(value)),
|
||||
|
||||
// 权限判断
|
||||
new SaTokenTagProcessor(prefix, "hasPermission", value -> stpLogic.hasPermission(value)),
|
||||
new SaTokenTagProcessor(prefix, "hasPermissionOr", value -> stpLogic.hasPermissionOr(toArray(value))),
|
||||
new SaTokenTagProcessor(prefix, "hasPermissionAnd", value -> stpLogic.hasPermissionAnd(toArray(value))),
|
||||
new SaTokenTagProcessor(prefix, "hasPermissionOr", value -> stpLogic.hasPermissionOr(toArray(value))),
|
||||
new SaTokenTagProcessor(prefix, "notPermission", value -> ! stpLogic.hasPermission(value)),
|
||||
new SaTokenTagProcessor(prefix, "lackPermission", value -> ! stpLogic.hasPermission(value))
|
||||
|
||||
));
|
||||
|
Loading…
Reference in New Issue
Block a user