今天重点讲解的是 ant-framework 核心代码的编写过程.
其中 ant-framework 是 ant 分布式框架的基础核心框架, 其中包括 CRUD,MVC 等一系列基类和模板. 另外定义了 spring,mybatis,wink 等底层框架扩展项目, 具体内容包括:
annotation 相关注解: 数据签名注解, 用户是否走 sso 登录注解等, 今天我们着重讲解一下 annotation 的编写.
提醒: 自定义 annotation 可以有效的将我们需要注解的类, 方法, 字段根据业务所需进行定义可配置化.
编写数字签名的 annotaion 的类, DataSign.java 内容如下:
- package com.sml.sz.common.annotation;
- import java.lang.annotation.ElementType;
- import java.lang.annotation.Retention;
- import java.lang.annotation.RetentionPolicy;
- import java.lang.annotation.Target;
- /**
- * 数据签名注解
- */
- @Target(ElementType.METHOD)
- @Retention(RetentionPolicy.RUNTIME)
- public @interface DataSign {
- }
编写 sso 单点登录认证的 annotion 类, IsLogin.java 内容如下:
- package com.sml.sz.common.annotation;
- import java.lang.annotation.ElementType;
- import java.lang.annotation.Retention;
- import java.lang.annotation.RetentionPolicy;
- import java.lang.annotation.Target;
- /**
- * 登录注解
- */
- @Target(ElementType.METHOD)
- @Retention(RetentionPolicy.RUNTIME)
- public @interface IsLogin {
- }
编写 Bean 的中文注解:
- package com.sml.sz.common.annotation;
- import java.lang.annotation.ElementType;
- import java.lang.annotation.Retention;
- import java.lang.annotation.RetentionPolicy;
- import java.lang.annotation.Target;
- /**
- * bean 中文名注解
- */
- @Target(ElementType.METHOD)
- @Retention(RetentionPolicy.RUNTIME)
- public @interface FieldName {
- String value();
- }
文章内容不写太多, 希望大家能够掌握每一个知识点, 这里的注解后面会全部定义在方法上, 具体的业务和实现后面会讲解到.
来源: http://www.bubuko.com/infodetail-2748137.html