EP框架之EP注解
EP框架本身还是并不是以造轮子为主,主要还是以辅助开发为主,开发框架底层还是基于开源框架Springboot+Mybatis在做,EP框架封装了很多有用的注解,下面对这些注解做一一说明。
SpringbootApplication启动类注解
启动类上的注解,目前主要是应用安全方面以及系统初始化方面的注解。
@EnableSQLFilter:防SQL注入注解。
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import({SQLFilterConfig.class})
public @interface EnableSQLFilter {
}
@EnableXSSFilter:防XSS攻击注解。
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import({XssConfig.class})
public @interface EnableXSSFilter {
}
@EnableAccessLog:开启访问日志注解,这块引入了junx.ep.access-log配置,详情可以参考io.github.junxworks.ep.core.security.access.AcConfig类。
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import({AccessConfig.class})
public @interface EnableAccessLog {
}
#需要在log4j的配置中加入一个logger
<AsyncLogger name="io.github.junxworks.ep.core.security.access.AccessFilter" level="INFO" additivity="true">
<appender-ref ref="accessInfo" /> #accessInfo为RollingFile配置
</AsyncLogger>
@EnableGlobalExceptionHandler:开启全局异常捕获,这个可加可不加,不加的话项目最好自己写一个全局异常捕获处理器。
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Import(GlobalExceptionHandler.class)
public @interface EnableGlobalExceptionHandler {
}
@EnableEPSys:开启EP基础系统模块,这个注解是复合注解,由@EnableBaseEPModules启用基础系统模块与@EnableEPShiroProxy启用shiro认证两个注解一同组成,可以拆开了用,这个注解必须加,会进行EP框架的初始化。
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import({ SpringContextUtils.class, EPBaseInitComponent.class })
@EnableBaseEPModules //EP基础系统模块
@EnableEPShiroProxy //开启EP认证
public @interface EnableEPSys {
/** 是否需要初始化EP,例如执行数据库脚本.第一次启动必须设置成true,后期没有更新EP版本的话,可以设置成false,加快系统启动速度 */
boolean init() default true;
}
Entity实体类注解
实体类注解,主要用来辅助ORM这块解析sql,可以基于实体类注解,做增删改查sql自动生成操作。
@Table(tableName="l_loan_refund",tableComment="")
public class LLoanRefund {
@PrimaryKey
@Column(name="id", type="BIGINT", length="19", nullable="false", comment="")
private Long id;
@Column(name="loanId", type="BIGINT", length="19", nullable="false", comment="l_loan_infox.loanId")
private Long loanId;
public Long getId(){
return this.id;
}
public void setId(Long id){
this.id = id;
}
public Long getLoanId(){
return this.loanId;
}
public void setLoanId(Long loanId){
this.loanId = loanId;
}
}
@Table:实体类表,主要是用来表示实体对应的数据库表名。
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Table {
String tableName();
String tableComment() default "";
}
@PrimaryKey:实体表唯一主键,默认是ID。
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface PrimaryKey {
}
@Column:实体表列名,有5个属性,除了name以外,其他都主要用于描述字段,给开发人员参考,并不会在程序中使用到,name字段,表示数据库表列名实际名称,可以与java属性不一致,例如java中是驼峰stuName,数据库的实际列名为stu_name。
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Column {
String name();
String type();
String length();
String nullable();
String comment();
}
Controller层注解
@EpLog:操作日志写入注解,如果controller层的method上有这个注解,则会往系统操作日志中异步写入日志,value为操作名称,建议"业务域-模块-操作"三级,记录关键操作日志,可以在系统菜单"系统管理->系统日志"中查询。
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface EpLog {
String value();
}