microservice-common

Microservice common project

License

License

GroupId

GroupId

com.github.xionghuicoder
ArtifactId

ArtifactId

microservice-common
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

microservice-common
Microservice common project
Project URL

Project URL

https://github.com/xionghuiCoder/microservice-common
Source Code Management

Source Code Management

https://github.com/xionghuiCoder/microservice-common

Download microservice-common

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.xionghuicoder/microservice-common/ -->
<dependency>
    <groupId>com.github.xionghuicoder</groupId>
    <artifactId>microservice-common</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.xionghuicoder/microservice-common/
implementation 'com.github.xionghuicoder:microservice-common:1.0.0'
// https://jarcasting.com/artifacts/com.github.xionghuicoder/microservice-common/
implementation ("com.github.xionghuicoder:microservice-common:1.0.0")
'com.github.xionghuicoder:microservice-common:jar:1.0.0'
<dependency org="com.github.xionghuicoder" name="microservice-common" rev="1.0.0">
  <artifact name="microservice-common" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.xionghuicoder', module='microservice-common', version='1.0.0')
)
libraryDependencies += "com.github.xionghuicoder" % "microservice-common" % "1.0.0"
[com.github.xionghuicoder/microservice-common "1.0.0"]

Dependencies

provided (7)

Group / Artifact Type Version
com.alibaba : fastjson jar 1.2.44
org.slf4j : slf4j-api jar 1.7.25
javax.servlet : javax.servlet-api jar 4.0.0
org.springframework : spring-core jar 5.0.2.RELEASE
org.springframework : spring-context jar 5.0.2.RELEASE
org.springframework : spring-webmvc jar 5.0.2.RELEASE
org.springframework : spring-tx jar 5.0.2.RELEASE

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

microservice-common

microservice-common是一个common project,该project包含一些公用的架构和工具类。

架构

  1. DAO相关架构,使用模板方法模式并定义前规则和后规则,可进行rule的校验
  2. Controller相关架构,自定义path注解以对应function请求参数,可以控制同一入口访问,方便统计pv、性能等

工具类

  1. 参数解析、异常处理等工具类
  2. md5加密工具类
  3. json, bean转换工具类

note

  1. JDK支持1.6或1.6+
  2. 在修改源码前,请导入googlestyle-java.xml以保证一致的代码格式

功能说明

1. 方法出入参自动打印

  @ParamLogAnnotation                                   //在需要打印出入参的方法上添加此注解
  public AopResponse test(AopRequest request){
    return new AopResponse(true,"success return.......");
  } 

调用方法后 结果输出:

 - 方法[test] 请求时间:2018-05-23 10:43:12| 入参:request:{"id":1,"name":"firstRequest","type":1001};
 - 方法[test] 请求时间:2018-05-23 10:43:12| 返回结果时间:2018-05-23 10:43:12| 出参:{"result":"success return.......","success":true}

2. 入参自动校验

入参实体:

public class SimpleBean {

  @NotNull
  private int id;

  @NotBlank
  @Size(min = 2, max = 8,message = "be care the name length ,it should between 2 and 8 !")
  private String name;

  @NotNull(message = "score should be not null")
  @DoubleVal   //自定义校验
  private Double score;
  
  get set ...
}

校验:

  @Test
  public void test(){
    SimpleBean myBean=new SimpleBean();
//    myBean.setName("abc");
//    myBean.setScore(1.23446);

    func(myBean);
  }
  
    private void func(SimpleBean bean){
      //******校验入参********
      ValidatorUtils.validate(bean);
      //******校验入参********
      
      System.out.println(JSONObject.toJSONString(bean));
    }

结果:

java.lang.IllegalArgumentException: 参数异常:SimpleBean.name : 不能为空

Versions

Version
1.0.0