From 03f28da9889ea132963a37af89d30435783d3854 Mon Sep 17 00:00:00 2001 From: click33 <2393584716@qq.com> Date: Mon, 19 Jun 2023 00:17:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=A0=87=E7=AD=BE=E6=96=B9?= =?UTF-8?q?=E8=A8=80=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=BC=BA=20ide=20=E4=BB=A3=E7=A0=81=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pj/SaTokenThymeleafDemoApplication.java | 3 +- .../src/main/resources/templates/index.html | 18 ++--- sa-token-doc/plugin/thymeleaf-extend.md | 4 +- .../thymeleaf/dialect/Sa-Token-Dialect.xml | 71 +++++++++++++++++++ .../thymeleaf/dialect/SaTokenDialect.java | 6 +- 5 files changed, 88 insertions(+), 14 deletions(-) create mode 100644 sa-token-plugin/sa-token-dialect-thymeleaf/src/main/java/cn/dev33/satoken/thymeleaf/dialect/Sa-Token-Dialect.xml diff --git a/sa-token-demo/sa-token-demo-thymeleaf/src/main/java/com/pj/SaTokenThymeleafDemoApplication.java b/sa-token-demo/sa-token-demo-thymeleaf/src/main/java/com/pj/SaTokenThymeleafDemoApplication.java index bcd9cd24..dbbd2eb0 100644 --- a/sa-token-demo/sa-token-demo-thymeleaf/src/main/java/com/pj/SaTokenThymeleafDemoApplication.java +++ b/sa-token-demo/sa-token-demo-thymeleaf/src/main/java/com/pj/SaTokenThymeleafDemoApplication.java @@ -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/"); } } \ No newline at end of file diff --git a/sa-token-demo/sa-token-demo-thymeleaf/src/main/resources/templates/index.html b/sa-token-demo/sa-token-demo-thymeleaf/src/main/resources/templates/index.html index 3886256b..9952fcc9 100644 --- a/sa-token-demo/sa-token-demo-thymeleaf/src/main/resources/templates/index.html +++ b/sa-token-demo/sa-token-demo-thymeleaf/src/main/resources/templates/index.html @@ -1,5 +1,5 @@ - + Sa-Token 集成 Thymeleaf 标签方言 @@ -9,28 +9,28 @@

Sa-Token 集成 Thymeleaf 标签方言 —— 测试页面

- 登录 + 登录 注销

- +

登录之后才能显示:value

不登录才能显示:value

- +

具有角色 admin 才能显示:value

同时具备多个角色才能显示:value

只要具有其中一个角色就能显示:value

-

不具有角色 admin 才能显示:value

- +

不具有角色 admin 才能显示:value

+

具有权限 user-add 才能显示:value

同时具备多个权限才能显示:value

只要具有其中一个权限就能显示:value

-

不具有权限 user-add 才能显示:value

- +

不具有权限 user-add 才能显示:value

+

从SaSession中取值:

- +
diff --git a/sa-token-doc/plugin/thymeleaf-extend.md b/sa-token-doc/plugin/thymeleaf-extend.md index ae8f00fd..9a17fd5c 100644 --- a/sa-token-doc/plugin/thymeleaf-extend.md +++ b/sa-token-doc/plugin/thymeleaf-extend.md @@ -72,7 +72,7 @@ public class SaTokenConfigure {

不具有角色 admin 才能显示: - value + value

``` @@ -92,7 +92,7 @@ public class SaTokenConfigure {

不具有权限 user-add 才能显示: - value + value

``` diff --git a/sa-token-plugin/sa-token-dialect-thymeleaf/src/main/java/cn/dev33/satoken/thymeleaf/dialect/Sa-Token-Dialect.xml b/sa-token-plugin/sa-token-dialect-thymeleaf/src/main/java/cn/dev33/satoken/thymeleaf/dialect/Sa-Token-Dialect.xml new file mode 100644 index 00000000..92b05bb0 --- /dev/null +++ b/sa-token-plugin/sa-token-dialect-thymeleaf/src/main/java/cn/dev33/satoken/thymeleaf/dialect/Sa-Token-Dialect.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sa-token-plugin/sa-token-dialect-thymeleaf/src/main/java/cn/dev33/satoken/thymeleaf/dialect/SaTokenDialect.java b/sa-token-plugin/sa-token-dialect-thymeleaf/src/main/java/cn/dev33/satoken/thymeleaf/dialect/SaTokenDialect.java index f2482e80..8bfc681e 100644 --- a/sa-token-plugin/sa-token-dialect-thymeleaf/src/main/java/cn/dev33/satoken/thymeleaf/dialect/SaTokenDialect.java +++ b/sa-token-plugin/sa-token-dialect-thymeleaf/src/main/java/cn/dev33/satoken/thymeleaf/dialect/SaTokenDialect.java @@ -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)) ));