--- 一个基于MyBatis的注解扩展 ---
- JSON字段映射,自动生成JSON字段TypeHandler。
<dependency>
<groupId>com.iakuil</groupId>
<artifactId>ez-mapper-processor</artifactId>
<version>0.0.2-RELEASE</version>
</dependency>
和Lombok等注解处理器类似的配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>com.iakuil</groupId>
<artifactId>ez-mapper-processor</artifactId>
<version>0.0.2-RELEASE</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
@JsonEntity
public class Bar {
private String name;
private String addr;
// getters and setters
}
重新编译后,target/classes目录下自动生成的TypeHandler:
@MappedTypes({Bar.class})
@MappedJdbcTypes({JdbcType.VARCHAR})
public class BarTypeHandler extends AbstractJsonTypeHandler<Bar> {
public BarTypeHandler() {
}
}
mybatis:
type-handlers-package: com.yourdomain.sample.yourpackage
如果是多模块的Maven工程,整个工程中不能有包名+类名完全一致的JSON映射对象。
比如:A模块有一个org.sample.Foo,B模块也有一个org.sample.Foo,并且两个类都添加了@JsonEntity
注解,编译时就会报错:Too many classes: org.sample.Foo
。
Copyright (c) 2021 iakuil.com