访问注解:
t = Class.forName(className);
//请求配置
Class<RequestMapping> annClass = org.springframework.web.bind.annotation.RequestMapping.class;
//api 解释
Class<ApiExplain> annApiExplain = com.sinky.api.ApiExplain.class;
//权限
Class<RequiresRoles> annRequiresRoles = org.apache.shiro.authz.annotation.RequiresRoles.class;
//请求
Annotation annotationClass = t.getAnnotation(annClass);
//api类注释
Annotation annotationClassDescription = t.getAnnotation(annApiExplain);
classStr = getAnnValues(annotationClass);
if (null == classStr)
continue;
System.out.println("类注解:" + classStr);
Method[] methods = t.getMethods();
for (Method m : methods)
{
methodStr =
getAnnValues(m.getAnnotation(annClass),
annotationClass,
m.getName(),
className,
m.getAnnotation(annApiExplain),
annotationClassDescription,
m.getAnnotation(annRequiresRoles)
);
if (null == methodStr)
continue;
System.out.println("方法:" + m.getName() + " " + methodStr);
}
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
自定义注解:
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.web.bind.annotation.Mapping;
/**
*
* 用于提供api注释
* <功能详细描述>
*
* @author liubeihua
* @version [版本号, 2016年1月13日]
*/
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Mapping
public @interface ApiExplain
{
/**
* 描述
* @return
*/
String description() default "";
String other() default "";
String value() default "";
}