• mybatis-generator 注释插件


    插件地址(https://github.com/suyin58/mybatis-generator-tddl/blob/master/generator-plugin/src/main/java/com/toolplat/generator/plugins/CommentGenerator.java)

    可以修改类注释、属性注释、方法注释等

    插件需要继承DefaultCommentGenerator

    public class CommentGenerator extends DefaultCommentGenerator {
    }
    View Code

    类注释需要重写addModelClassComment方法

      /**
         * set model comment from table remark
         * @param topLevelClass
         * @param introspectedTable
         */
        @Override
        public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    
            String auth = properties.getProperty("author");
            String tableDesc = introspectedTable.getRemarks();
            topLevelClass.addJavaDocLine("/**");
            topLevelClass.addJavaDocLine(" * " + tableDesc);
            if (null != auth && auth.length() > 0) {
                topLevelClass.addJavaDocLine(" * @author " + auth);
            }
            topLevelClass.addJavaDocLine(" */");
        }
    View Code

    属性注释需要重写addFieldComment方法

    /**
         * set field comment from field remark
         * @param field
         * @param introspectedTable
         * @param introspectedColumn
         */
        @Override
        public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
            String remark = introspectedColumn.getRemarks();
            field.addJavaDocLine("/**");
            field.addJavaDocLine(" * " + remark);
            field.addJavaDocLine(" */");
        }
    View Code

    mapper方法注释需要重写addGeneralMethodComment方法

     /**
         * remove java mapping coment
         *
         * @param method
         * @param introspectedTable
         */
        @Override
        public void addGeneralMethodComment(Method method, IntrospectedTable introspectedTable) {
    //        method.addJavaDocLine("/**");
    //        method.addJavaDocLine(" * auto method:" + method.getName());
    //        if (method.getParameters() != null && method.getParameters().size() > 0) {
    //            for (Parameter param : method.getParameters()) {
    //                method.addJavaDocLine(" * @param " + param.getName());
    //            }
    //        }
    //        Optional<FullyQualifiedJavaType> ret = method.getReturnType();
    //        if (ret.isPresent()) {
    //            method.addJavaDocLine(" * @return " + ret.get().getShortName());
    //        }
    //        method.addJavaDocLine(" */");
        }
    View Code

    生成效果:

    package com.toolplat.demo.domain;
    
    import java.io.Serializable;
    import java.util.Date;
    import lombok.AllArgsConstructor;
    import lombok.Builder;
    import lombok.Data;
    import lombok.NoArgsConstructor;
    import lombok.ToString;
    
    /**
     * 单个uk测试
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @ToString
    public class TableOneUniqueKeyPO implements Serializable {
        private static final long serialVersionUID = 21323185007909L;
    
        /**
         * 多群主键
         */
        private Long orgId;
    
        /**
         * 多码
         */
        private String code;
    
        /**
         * id
         */
        private Long id;
    
        /**
         * 创建时间
         */
        private Date gmtCreate;
    
        /**
         * 修改时间
         */
        private Date gmtModified;
    
        /**
         * 会话ID
         */
        private String cid;
    }
    实体类

    mapper方法:

    package com.toolplat.demo.dao;
    
    import com.toolplat.demo.domain.TableOneUniqueKeyPO;
    import com.toolplat.demo.domain.TableOneUniqueKeyPOExample;
    import java.util.List;
    import org.apache.ibatis.annotations.Param;
    
    public interface TableOneUniqueKeyMapper {
        long countByExample(TableOneUniqueKeyPOExample example);
    
        int deleteByExample(TableOneUniqueKeyPOExample example);
    
        int deleteByPrimaryKey(@Param("orgId") Long orgId, @Param("code") String code);
    
        int insert(TableOneUniqueKeyPO record);
    
        int insertSelective(TableOneUniqueKeyPO record);
    
        List<TableOneUniqueKeyPO> selectByExample(TableOneUniqueKeyPOExample example);
    
        TableOneUniqueKeyPO selectByExampleForUpdate(TableOneUniqueKeyPOExample example);
    
        TableOneUniqueKeyPO selectByPrimaryKey(@Param("orgId") Long orgId, @Param("code") String code);
    
        TableOneUniqueKeyPO selectByPrimaryKeyForUpdate(@Param("orgId") Long orgId, @Param("code") String code);
    
        int updateByExampleSelective(@Param("record") TableOneUniqueKeyPO record, @Param("example") TableOneUniqueKeyPOExample example);
    
        int updateByExample(@Param("record") TableOneUniqueKeyPO record, @Param("example") TableOneUniqueKeyPOExample example);
    
        int updateByPrimaryKeySelective(TableOneUniqueKeyPO record);
    
        int updateByPrimaryKey(TableOneUniqueKeyPO record);
    
        TableOneUniqueKeyPO selectByUniqueKey(@Param("orgId") Long orgId, @Param("code") String code);
    
        TableOneUniqueKeyPO selectByUniqueKeyForUpdate(@Param("orgId") Long orgId, @Param("code") String code);
    
        int updateByUniqueKeySelective(TableOneUniqueKeyPO record);
    
        int deleteByUniqueKey(@Param("orgId") Long orgId, @Param("code") String code);
    
        int batchInsert(@Param("list") List<TableOneUniqueKeyPO> list);
    
        int upsertByPrimaryKey(TableOneUniqueKeyPO record);
    
        int upsertByUniqueKey(TableOneUniqueKeyPO record);
    }
    mapper方法注释
  • 相关阅读:
    Algorithm Gossip (37) 快速排序法 ( 一 )
    Algorithm Gossip (36) Heap排序法( 堆排序 )
    Algorithm Gossip (35) Shaker法
    Algorithm Gossip (34) 希尔排序
    AlgorithmGossip (33) 选择、插入、气泡排序
    Algorithm Gossip (32) 得分排行
    Algorithm Gossip (31) 数字拆解(dp问题)
    Algorithm Gossip (30) m元素集合的 n 个元素子集
    Algorithm Gossip (29) 产生可能的集合
    Algorithm Gossip (27) 排列组合
  • 原文地址:https://www.cnblogs.com/loveyou/p/13883246.html
Copyright © 2020-2023  润新知