一些自定义的mybatis-generator 代码生成器部分的插件:
1、自定义的序列化 类文件 插件 ;
2、mysql oracle 两种数据源的分页配置插件 根据 _databaseId 的区别来区分当前数据源是oracle还是mysql,方便数据迁移过程中的分页逻辑不报错;
3、取消 Example 类文件的生成,在进行代码生成器的过程中,生成 selectCountByMap selectListByMap 两种方法,代替 Example 方法的生成 ;
4、自定义注释部分(实体类entity生成过程中,将配置的数据库部分的注释部分生成,关键节点的注解部分生成);
取消 Example 类的生成,改为自定义生成 selectCountByMap selectListByMap 两个方法来替代(原因为生成 Example类的情况下,代码重用度过低,不好进行维护操作);
取消使用分页插件对mybatis 进行分页操作,而是通过使用 代码生成器生成对应的 sql段落,通过 _databaseId 进行数据源部分的区分;
如果数据库的表结构设计部分包含大量的注释(ramark)部分,那么在生成实体类过程中,将这一部分数据库表结构的注释部分加上,这样的话,有助于理解各个字段的含义;
部分生成效果展示:
@MyBatisTableAnnotation(name = "demo_attachment", namespace = "com.alexgaoyh.MutiModule.Dubbo.RWSeperate.persist.manager.demo.upload.DemoAttachmentMapper", remarks = "测试模块-文件上传 ", aliasName = "demo_attachment demo_attachment")public class DemoAttachment extends BaseEntity implements Serializable { /** * 名称,所属表字段为demo_attachment.NAME */ @MyBatisColumnAnnotation(name = "NAME", value = "demo_attachment_NAME", chineseNote = "名称", tableAlias = "demo_attachment") private String name; private static final long serialVersionUID = 1L; public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getClass().getSimpleName()); sb.append(" ["); sb.append("Hash = ").append(hashCode()); sb.append(", name=").append(name); sb.append("]"); return sb.toString(); }}
import com.alexgaoyh.MutiModule.Dubbo.RWSeperate.persist.manager.demo.upload.DemoAttachment;import java.util.List;import java.util.Map;public interface DemoAttachmentMapper { int deleteByPrimaryKey(String id); int selectCountByMap(Map
demo_attachment.ID as demo_attachment_ID, demo_attachment.DELETE_FLAG as demo_attachment_DELETE_FLAG, demo_attachment.CREATE_TIME as demo_attachment_CREATE_TIME, demo_attachment.NAME as demo_attachment_NAME delete from demo_attachment where ID = #{id,jdbcType=VARCHAR} insert into demo_attachment (ID, DELETE_FLAG, CREATE_TIME, NAME) values (#{id,jdbcType=VARCHAR}, #{deleteFlag,jdbcType=VARCHAR,typeHandler=com.alexgaoyh.MutiModule.Dubbo.RWSeperate.persist.util.enums.handler.DeleteFlagEnumHandler}, #{createTime,jdbcType=VARCHAR,typeHandler=com.alexgaoyh.MutiModule.Dubbo.RWSeperate.persist.util.GMT.handler.GMTDateTransHandler}, #{name,jdbcType=VARCHAR}) insert into demo_attachment ID, DELETE_FLAG, CREATE_TIME, NAME, #{id,jdbcType=VARCHAR}, #{deleteFlag,jdbcType=VARCHAR,typeHandler=com.alexgaoyh.MutiModule.Dubbo.RWSeperate.persist.util.enums.handler.DeleteFlagEnumHandler}, #{createTime,jdbcType=VARCHAR,typeHandler=com.alexgaoyh.MutiModule.Dubbo.RWSeperate.persist.util.GMT.handler.GMTDateTransHandler}, #{name,jdbcType=VARCHAR}, update demo_attachment where ID = #{id,jdbcType=VARCHAR} DELETE_FLAG = #{deleteFlag,jdbcType=VARCHAR,typeHandler=com.alexgaoyh.MutiModule.Dubbo.RWSeperate.persist.util.enums.handler.DeleteFlagEnumHandler}, CREATE_TIME = #{createTime,jdbcType=VARCHAR,typeHandler=com.alexgaoyh.MutiModule.Dubbo.RWSeperate.persist.util.GMT.handler.GMTDateTransHandler}, NAME = #{name,jdbcType=VARCHAR}, update demo_attachment set DELETE_FLAG = #{deleteFlag,jdbcType=VARCHAR,typeHandler=com.alexgaoyh.MutiModule.Dubbo.RWSeperate.persist.util.enums.handler.DeleteFlagEnumHandler}, CREATE_TIME = #{createTime,jdbcType=VARCHAR,typeHandler=com.alexgaoyh.MutiModule.Dubbo.RWSeperate.persist.util.GMT.handler.GMTDateTransHandler}, NAME = #{name,jdbcType=VARCHAR} where ID = #{id,jdbcType=VARCHAR} select * from ( select row_.*, rownum rownum_ from ( #{page.begin} and rownum_ <= #{page.end} ]]> limit #{page.begin} , #{page.length} demo_attachment.ID = #{id,jdbcType=VARCHAR} demo_attachment.DELETE_FLAG = #{deleteFlag,jdbcType=VARCHAR,typeHandler=com.alexgaoyh.MutiModule.Dubbo.RWSeperate.persist.util.enums.handler.DeleteFlagEnumHandler} demo_attachment.CREATE_TIME = #{createTime,jdbcType=VARCHAR,typeHandler=com.alexgaoyh.MutiModule.Dubbo.RWSeperate.persist.util.GMT.handler.GMTDateTransHandler} demo_attachment.NAME = #{name,jdbcType=VARCHAR}