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 73065190..4ff09fc6 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 @@ -51,12 +51,12 @@ public class SaTokenDialect extends AbstractProcessorDialect { * 构造方言对象,使用自定义参数 * * @param name 方言名称 - * @param recedence 优先级 + * @param precedence 优先级 * @param stpLogic 使用的 StpLogic 对象 */ - public SaTokenDialect(String name, int recedence, StpLogic stpLogic) { + public SaTokenDialect(String name, int precedence, StpLogic stpLogic) { // 名称、前缀、优先级 - super(name, name, recedence); + super(name, name, precedence); this.stpLogic = stpLogic; } @@ -65,24 +65,24 @@ public class SaTokenDialect extends AbstractProcessorDialect { */ @Override public Set getProcessors(String prefix) { - return new HashSet(Arrays.asList( - // 登录判断 - new SaTokenTagProcessor(prefix, "login", value -> stpLogic.isLogin()), - new SaTokenTagProcessor(prefix, "notLogin", value -> stpLogic.isLogin() == false), - - // 角色判断 - 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, "lackRole", value -> stpLogic.hasRole(value) == false), - - // 权限判断 - 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, "lackPermission", value -> stpLogic.hasPermission(value) == false) - - )); + return new HashSet<>(Arrays.asList( + // 登录判断 + new SaTokenTagProcessor(prefix, "login", value -> stpLogic.isLogin()), + new SaTokenTagProcessor(prefix, "notLogin", value -> ! stpLogic.isLogin()), + + // 角色判断 + 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, "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, "lackPermission", value -> ! stpLogic.hasPermission(value)) + + )); } /** @@ -92,7 +92,7 @@ public class SaTokenDialect extends AbstractProcessorDialect { */ public String[] toArray(String str) { List list = SaFoxUtil.convertStringToList(str); - return list.toArray(new String[list.size()]); + return list.toArray(new String[0]); } } diff --git a/sa-token-plugin/sa-token-dialect-thymeleaf/src/main/java/cn/dev33/satoken/thymeleaf/dialect/SaTokenTagProcessor.java b/sa-token-plugin/sa-token-dialect-thymeleaf/src/main/java/cn/dev33/satoken/thymeleaf/dialect/SaTokenTagProcessor.java index 19bc1859..fe6660c3 100644 --- a/sa-token-plugin/sa-token-dialect-thymeleaf/src/main/java/cn/dev33/satoken/thymeleaf/dialect/SaTokenTagProcessor.java +++ b/sa-token-plugin/sa-token-dialect-thymeleaf/src/main/java/cn/dev33/satoken/thymeleaf/dialect/SaTokenTagProcessor.java @@ -34,13 +34,13 @@ public class SaTokenTagProcessor extends AbstractAttributeTagProcessor { Function fun; - public SaTokenTagProcessor(final String dialectPrefix, String arrtName, Function fun) { + public SaTokenTagProcessor(final String dialectPrefix, String attrName, Function fun) { super( TemplateMode.HTML, // This processor will apply only to HTML mode dialectPrefix, // Prefix to be applied to name for matching null, // No tag name: match any tag name false, // No prefix to be applied to tag name - arrtName, // Name of the attribute that will be matched + attrName, // Name of the attribute that will be matched true, // Apply dialect prefix to attribute name 10000, // Precedence (inside dialect's own precedence) true); // Remove the matched attribute afterwards @@ -53,9 +53,9 @@ public class SaTokenTagProcessor extends AbstractAttributeTagProcessor { final AttributeName attributeName, final String attributeValue, final IElementTagStructureHandler structureHandler) { // 执行表达式返回值为false,则删除这个标签 - if(this.fun.apply(attributeValue) == false) { + if( ! this.fun.apply(attributeValue)) { structureHandler.removeElement(); - }; + } } } \ No newline at end of file