首页 > 其他 > 详细

mybatis-generator 注释插件

时间:2020-10-27 12:23:53      阅读:51      评论:0      收藏:0      [点我收藏+]

插件地址(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方法注释

 

mybatis-generator 注释插件

原文:https://www.cnblogs.com/loveyou/p/13883246.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!