• easycode生成代码模板配置


    实体:

    ##引入宏定义
    $!define##使用宏定义设置回调(保存位置与文件后缀)
    
    $!autoImport
    import io.swagger.annotations.ApiModel;
    import io.swagger.annotations.ApiModelProperty;
    import lombok.Data;
    import lombok.NoArgsConstructor;
    import java.io.Serializable;
    
    @Data
    @NoArgsConstructor
    @ApiModel("#if($!{tableInfo.comment})$!{tableInfo.comment}实体类#end")
    public class $!{tableInfo.name} implements Serializable {
    private static final long serialVersionUID = $!tool.serial();
    #foreach($column in $tableInfo.fullColumn)
    
        @ApiModelProperty("#if(${column.comment})${column.comment}#end")
        private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
    #end}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    mapper.xml:

    ##引入mybatis支持
    $!{mybatisSupport.vm}
    
    ##设置保存名称与保存位置
    $!callback.setFileName($tool.append($!{tableInfo.name}, "Dao.xml"))
    $!callback.setSavePath($tool.append($modulePath, "/src/main/resources/mapper"))
    
    ##拿到主键
    #if(!$tableInfo.pkColumn.isEmpty())
        #set($pk = $tableInfo.pkColumn.get(0))
    #end
    
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="$!{tableInfo.savePackageName}.dao.$!{tableInfo.name}Dao">
    
        <resultMap id="BaseResultMap" type="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}">
            <!--@Table $!{tableInfo.obj.name}-->
    #foreach($column in $tableInfo.fullColumn)
            <result property="$!column.name" column="$!column.obj.name" jdbcType="$!column.ext.jdbcType"/>
    #end
        </resultMap>
    
        <!--查询单个-->
        <select id="queryById" resultMap="BaseResultMap">
            select
              #allSqlColumn()
    
            from $!tableInfo.obj.name
            where $!pk.obj.name = #{$!pk.name}
        </select>
    
      
    
        <!--通过实体作为筛选条件查询-->
        <select id="queryAll" resultMap="BaseResultMap">
            select
              #allSqlColumn()
    
            from $!{tableInfo.obj.parent.name}.$!tableInfo.obj.name
        </select>
    
        <!--新增所有列-->
        <insert id="insert" >
            insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)
            values (#foreach($column in $tableInfo.otherColumn)#{$!{column.name}}#if($velocityHasNext), #end#end)
        </insert>
    
        <insert id="insertBatch">
            insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)
            values
            <foreach collection="entities" item="entity" separator=",">
            (#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($velocityHasNext), #end#end)
            </foreach>
        </insert>
    
        <insert id="insertOrUpdateBatch" >
            insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)
            values
            <foreach collection="entities" item="entity" separator=",">
                (#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($velocityHasNext), #end#end)
            </foreach>
            on duplicate key update
            #foreach($column in $tableInfo.otherColumn)$!column.obj.name = values($!column.obj.name)#if($velocityHasNext),
            #end#end
    
        </insert>
    
        <!--通过主键修改数据-->
        <update id="update">
            update $!{tableInfo.obj.name}
            <set>
    #foreach($column in $tableInfo.otherColumn)
                <if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
                    $!column.obj.name = #{$!column.name},
                </if>
    #end
            </set>
            where $!pk.obj.name = #{$!pk.name}
        </update>
    
        <!--通过主键删除-->
        <delete id="deleteById">
            delete from $!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name}
        </delete>
    
    </mapper>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87

    mapper

    ##定义初始变量
    #set($tableName = $tool.append($tableInfo.name, "Dao"))
    ##设置回调
    $!callback.setFileName($tool.append($tableName, ".java"))
    $!callback.setSavePath($tool.append($tableInfo.savePath, "/dao"))
    
    ##拿到主键
    #if(!$tableInfo.pkColumn.isEmpty())
        #set($pk = $tableInfo.pkColumn.get(0))
    #end
    
    #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}dao;
    
    import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
    import org.apache.ibatis.annotations.Param;
    import org.springframework.data.domain.Pageable;
    import java.util.List;
    
    /**
     * $!{tableInfo.comment}($!{tableInfo.name})表数据库访问层
     *
     * @author $!author
     * @since $!time.currTime()
     */
    public interface $!{tableName} {
    
        /**
         * 通过ID查询单条数据
         *
         * @param $!pk.name 主键
         * @return 实例对象
         */
        $!{tableInfo.name} queryById($!pk.shortType $!pk.name);
        
        /**
         * 查询列表 
         *
         * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
         * @return 返回所有符合条件的数据
         */
        List<$!{tableInfo.name}> queryAll($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}))
    
       
        /**
         * 新增数据
         *
         * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
         * @return 影响行数
         */
        int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
    
        /**
         * 批量新增数据(MyBatis原生foreach方法)
         *
         * @param entities List<$!{tableInfo.name}> 实例对象列表
         * @return 影响行数
         */
        int insertBatch(@Param("entities") List<$!{tableInfo.name}> entities);
    
        /**
         * 批量新增或按主键更新数据(MyBatis原生foreach方法)
         *
         * @param entities List<$!{tableInfo.name}> 实例对象列表
         * @return 影响行数
         * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参
         */
        int insertOrUpdateBatch(@Param("entities") List<$!{tableInfo.name}> entities);
    
        /**
         * 修改数据
         *
         * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
         * @return 影响行数
         */
        int update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
    
        /**
         * 通过主键删除数据
         *
         * @param $!pk.name 主键
         * @return 影响行数
         */
        int deleteById($!pk.shortType $!pk.name);
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
  • 相关阅读:
    基于JavaSwing开发简单的学生信息管理系统(增删改查SQLServer数据库)+报告
    无法定位程序输入点packetgetreadevent于动态链接库wpcap.dll上
    C++与QML交互总结二
    剑指offer刷题笔记 开端
    Docker容器实现MySQL主从复制
    TypeScript 基本语法
    SSM注解大全
    中兴助力低空经济发展,携山东移动完成5G-A通感一体商用验证
    C Primer Plus(6) 中文版 第13章 文件输入/输出 13.7 其他标准I/O函数 13.8 关键概念 13.9 本章小结
    java-net-php-python-ssm大学生综合测评系统的设计与实现计算机毕业设计程序
  • 原文地址:https://blog.csdn.net/Lao_Wu66/article/details/132758459