[关闭]
@zongwu 2017-08-17T07:45:41.000000Z 字数 1903 阅读 324

在此处输入标题

未分类


1、项目依赖如下包:

  1. <dependency>
  2. <groupId>com.ipudong</groupId>
  3. <artifactId>api-client</artifactId>
  4. <version>1.0.3</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.reflections</groupId>
  8. <artifactId>reflections</artifactId>
  9. <version>0.9.11</version>
  10. <type>jar</type>
  11. </dependency>

2、新增注解:

2.1、注解使用用例(一):

@ApiCenterOperation(
        name = "ac.user.fetch",
        version = "1.0",
        author = "陈俊棋",
        description = "通过手机号码查询用户的信息",
        dependLogin = false
)
Result<UserDO> getByMobile(@ApiCenterParam("mobile") String mobile);

2.2、注解使用用例(二):

@ApiCenterOperation(
        name = "ac.user.fetch.list",
        version = "1.0",
        author = "陈俊棋",
        description = "通过手机号码查询用户的信息",
        dependLogin = false
)
Result<List<UserInfoPOJO>> fetchUserInfoList(@ApiCenterParam("userQuery") UserQuery userQuery);

2.3、生成配置文件代码:

  1. public class ApiGenerator {
  2. // 配置dubbo服务接口所在的包名
  3. private static final String packageName = "com.ipudong.pdserver.client.service";
  4. // 作用域 - 用于划分来源
  5. private static final String scope = "pdserver";
  6. public static void main(String[] args) {
  7. System.out.println(">>>> api generator begin <<<<");
  8. new ApiCenterGenerator(packageName, scope).generate();
  9. System.out.println(">>>> api generator end <<<<");
  10. }
  11. }

3、注意事项:

1、@ApiCenterParamvalue必须与参数名保持一致,举例:@ApiCenterParam("mobile") String mobile 中的两个mobile。
2、参见注解使用用例(二),若是传入参数是POJO则要求POJO的field都需是java.lang类型。否则可能会导致apicenter部分无法正确解析(即不支持POJO内嵌套POJO)。
3、需要明确标记@ApiCenterOperation@ApiCenterParam的接口才会导出注解。

4、注解说明

4.1、ApiCenterOperation

  1. @Target({ElementType.METHOD})
  2. @Retention(RetentionPolicy.RUNTIME)
  3. public @interface ApiCenterOperation {
  4. String name();//接口名称
  5. String version();//接口版本
  6. String author() default "";//作者
  7. String description() default "";//接口描述
  8. boolean dependLogin() default true;//依赖登录
  9. boolean export() default true;//是否导出到配置文件
  10. }

4.2、ApiCenterParam

  1. @Retention(RetentionPolicy.RUNTIME)
  2. @Target({ElementType.PARAMETER})
  3. public @interface ApiCenterParam {
  4. String value();//字段名称
  5. boolean canEmpty() default false;//是否选填
  6. String def() default "";//默认值
  7. String desc() default "";//字段说明
  8. boolean pojo() default false;//是否pojo
  9. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注