自定义注解示例:
package com.flmall.base.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Inherited
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface PermissionTag {
String name();
/**
* 1表示菜单
* 2表示权限
* -1隐藏菜单
* */
int type();
}
使用示例:
@PermissionTag(name = "权限管理",type = 1)
public void index() {
render("permission_list.html");
}
获取注解值示例:
private void setValue(SystemPermission permission, Action action) {
PermissionTag remark = action.getMethod().getAnnotation(PermissionTag.class);
if (remark != null && StrKit.notBlank(remark.name())) {
permission.setType(remark.type());
permission.setName(remark.name());
}
}