• EasyCode的Mybatis终极版模板


    EasyCode的Mybatis终极版

    距离我第一次上手EasyCode已经有一年的时间


    我的两篇文章,Easy Code的使用教程(带模板)以及另外一篇MyBatis-Plus的easycode模板,看的人还是挺多的,也有反映Easy Code的使用教程(带模板)的vm自动化有问题的,因此我今天重塑了一下我的vm,这次将更加强大!!!写这篇文章,一来是解决问题,二来是记录一下我写的vm。


    在这里插入图片描述

    提醒一下,看这篇文章,如果你已经有EasyCode使用基础,只是来拿一下模板,可以直接看,如果你同时想知道知道到底怎么用easy code,请先看Easy Code的使用教程(带模板),本文可看作Easy Code的使用教程(带模板)的后续升级版。

    见证一下?

    非常标准的domain,mapper,service,serviceimpl,controller,yaml,xml,以及一个banner图,全部都有,并且保证无bug,以阿里开发手册为指导,制造了具有restful风格的API,统一返回类。

    在这里插入图片描述
    返回json

    在这里插入图片描述

    需要的jar包

     <dependencies>
            <dependency>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-starter-webartifactId>
            dependency>
            <dependency>
                <groupId>org.mybatis.spring.bootgroupId>
                <artifactId>mybatis-spring-boot-starterartifactId>
                <version>2.2.2version>
            dependency>
            <dependency>
                <groupId>com.alibabagroupId>
                <artifactId>druid-spring-boot-starterartifactId>
                <version>1.2.14version>
            dependency>
    
            <dependency>
                <groupId>com.mysqlgroupId>
                <artifactId>mysql-connector-jartifactId>
                <scope>runtimescope>
            dependency>
            <dependency>
                <groupId>org.projectlombokgroupId>
                <artifactId>lombokartifactId>
                <optional>trueoptional>
            dependency>
            <dependency>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-starter-testartifactId>
                <scope>testscope>
            dependency>
        dependencies>
    
    • 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

    domain.java.vm

    ##引入宏定义
    $!{define.vm}
    
    ##使用宏定义设置回调(保存位置与文件后缀)
    #save("/domain", ".java")
    
    ##使用宏定义设置包后缀
    #setPackageSuffix("domain")
    
    ##使用全局变量实现默认包导入
    $!{autoImport.vm}
    import lombok.AllArgsConstructor;
    import lombok.Data;
    import lombok.NoArgsConstructor;
    
    import java.io.Serializable;
    
    ##使用宏定义实现类注释信息
    #tableComment("实体类")
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public class $!{tableInfo.name} implements Serializable {
    private static final long serialVersionUID = $!tool.serial();
    #foreach($column in $tableInfo.fullColumn)
    #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
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30

    mapper.java.vm

    ##定义初始变量
    #set($tableName = $tool.append($tableInfo.name, "Mapper"))
    ##设置回调
    $!callback.setFileName($tool.append($tableName, ".java"))
    $!callback.setSavePath($tool.append($tableInfo.savePath, "/mapper"))
    
    ##拿到主键
    #if(!$tableInfo.pkColumn.isEmpty())
        #set($pk = $tableInfo.pkColumn.get(0))
    #end
    
    #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}mapper;
    
    import $!{tableInfo.savePackageName}.domain.$!{tableInfo.name};
    import org.apache.ibatis.annotations.Mapper;
    import org.apache.ibatis.annotations.Param;
    
    import java.util.List;
    
    /**
     * $!{tableInfo.comment}($!{tableInfo.name})表数据库访问层
     *
     * @author $!author
     * @since $!time.currTime()
     */
    @Mapper
    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 总行数
             */
            long count($!{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
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95

    mapper.xml.vm

    ##引入mybatis支持
    $!{mybatisSupport.vm}
    
    ##设置保存名称与保存位置
    $!callback.setFileName($tool.append($!{tableInfo.name}, "Mapper.xml"))
    $!callback.setSavePath($tool.append($modulePath, "/src/main/resources/mapper"))
    
    ##拿到主键
    #if(!$tableInfo.pkColumn.isEmpty())
        #set($pk = $tableInfo.pkColumn.get(0))
    #end
    
    
    DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="$!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper">
    
        <resultMap type="$!{tableInfo.savePackageName}.domain.$!{tableInfo.name}" id="$!{tableInfo.name}Map">
    #foreach($column in $tableInfo.fullColumn)
            <result property="$!column.name" column="$!column.obj.name" jdbcType="$!column.ext.jdbcType"/>
    #end
        resultMap>
    
        
        <select id="queryById" resultMap="$!{tableInfo.name}Map">
            select
              #allSqlColumn()
    
            from $!tableInfo.obj.name
            where $!pk.obj.name = #{$!pk.name}
        select>
    
        
        <select id="queryAll" resultMap="$!{tableInfo.name}Map">
            select
              #allSqlColumn()
    
            from $!tableInfo.obj.name
            <where>
    #foreach($column in $tableInfo.fullColumn)
                <if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
                    and $!column.obj.name = #{$!column.name}
                if>
    #end
            where>
        select>
    
        
        <select id="count" resultType="java.lang.Long">
            select count(*)
            from $!tableInfo.obj.name
            <where>
    #foreach($column in $tableInfo.fullColumn)
                <if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
                    and $!column.obj.name = #{$!column.name}
                if>
    #end
            where>
        select>
    
        
        <insert id="insert" keyProperty="$!pk.name" useGeneratedKeys="true">
            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" keyProperty="$!pk.name" useGeneratedKeys="true">
            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" keyProperty="$!pk.name" useGeneratedKeys="true">
            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
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105

    service.java.vm

    ##定义初始变量
    #set($tableName = $tool.append($tableInfo.name, "Service"))
    ##设置回调
    $!callback.setFileName($tool.append($tableName, ".java"))
    $!callback.setSavePath($tool.append($tableInfo.savePath, "/service"))
    
    ##拿到主键
    #if(!$tableInfo.pkColumn.isEmpty())
        #set($pk = $tableInfo.pkColumn.get(0))
    #end
    
    #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service;
    
    import $!{tableInfo.savePackageName}.domain.$!{tableInfo.name};
    import $!{tableInfo.savePackageName}.util.R;
    
    /**
     * $!{tableInfo.comment}($!{tableInfo.name})表服务接口
     *
     * @author $!author
     * @since $!time.currTime()
     */
    public interface $!{tableName} {
    
            /**
             * 通过ID查询单条数据
             *
             * @param $!pk.name 主键
             * @return 实例对象
             */
            R queryById($!pk.shortType $!pk.name);
    
            /**
             * 全查询
             *
             * @param $!tool.firstLowerCase($!{tableInfo.name}) 筛选条件
             * @return 查询结果
             */
            R queryAll($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
    
            /**
             * 新增数据
             *
             * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
             * @return 实例对象
             */
            R insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
    
            /**
             * 修改数据
             *
             * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
             * @return 实例对象
             */
            R update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
    
            /**
             * 通过主键删除数据
             *
             * @param $!pk.name 主键
             * @return 是否成功
             */
            R 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

    serviceimpl.java.vm

    ##定义初始变量
    #set($tableName = $tool.append($tableInfo.name, "ServiceImpl"))
    ##设置回调
    $!callback.setFileName($tool.append($tableName, ".java"))
    $!callback.setSavePath($tool.append($tableInfo.savePath, "/service/impl"))
    
    ##拿到主键
    #if(!$tableInfo.pkColumn.isEmpty())
        #set($pk = $tableInfo.pkColumn.get(0))
    #end
    
    #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service.impl;
    
    import $!{tableInfo.savePackageName}.domain.$!{tableInfo.name};
    import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper;
    import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
    import $!{tableInfo.savePackageName}.util.R;
    import org.springframework.stereotype.Service;
    
    import javax.annotation.Resource;
    
    /**
     * $!{tableInfo.comment}($!{tableInfo.name})表服务实现类
     *
     * @author $!author
     * @since $!time.currTime()
     */
    @Service("$!tool.firstLowerCase($!{tableInfo.name})Service")
    public class $!{tableName} implements $!{tableInfo.name}Service {
    @Resource
    private $!{tableInfo.name}Mapper $!tool.firstLowerCase($!{tableInfo.name})Mapper;
    
    /**
     * 通过ID查询单条数据
     *
     * @param $!pk.name 主键
     * @return 实例对象
     */
    @Override
    public R queryById($!pk.shortType $!pk.name) {
            return R.ok().setData(this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.queryById($!pk.name));
            }
    
    /**
     * 全查询
     *
     * @param $!{tool.firstLowerCase($tableInfo.name)} 筛选条件
     * @return 查询结果
     */
    @Override
    public R queryAll($!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
            return R.ok().setData(this.$!{tool.firstLowerCase($tableInfo.name)}Mapper.queryAll($!{tool.firstLowerCase($tableInfo.name)}));
            }
    
    /**
     * 新增数据
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
     * @return 实例对象
     */
    @Override
    public R insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
            this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.insert($!tool.firstLowerCase($!{tableInfo.name}));
            return R.ok().setData($!tool.firstLowerCase($!{tableInfo.name}));
            }
    
    /**
     * 修改数据
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
     * @return 实例对象
     */
    @Override
    public R update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
            this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.update($!tool.firstLowerCase($!{tableInfo.name}));
            return R.ok().setData(this.queryById($!{tool.firstLowerCase($!{tableInfo.name})}.get$!tool.firstUpperCase($pk.name)()));
            }
    
    /**
     * 通过主键删除数据
     *
     * @param $!pk.name 主键
     * @return 是否成功
     */
    @Override
    public R deleteById($!pk.shortType $!pk.name) {
            boolean del = this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.deleteById($!pk.name) > 0;
            return R.ok().setData(del);
            }
            }
    
    • 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
    • 88
    • 89
    • 90

    controller.java.vm

    ##定义初始变量
    #set($tableName = $tool.append($tableInfo.name, "Controller"))
    ##设置回调
    $!callback.setFileName($tool.append($tableName, ".java"))
    $!callback.setSavePath($tool.append($tableInfo.savePath, "/controller"))
    ##拿到主键
    #if(!$tableInfo.pkColumn.isEmpty())
        #set($pk = $tableInfo.pkColumn.get(0))
    #end
    
    #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller;
    
    import $!{tableInfo.savePackageName}.domain.$!{tableInfo.name};
    import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
    import $!{tableInfo.savePackageName}.util.R;
    import org.springframework.web.bind.annotation.*;
    
    import javax.annotation.Resource;
    
    /**
     * $!{tableInfo.comment}($!{tableInfo.name})表控制层
     *
     * @author $!author
     * @since $!time.currTime()
     */
    @RestController
    @RequestMapping("$!tool.firstLowerCase($tableInfo.name)")
    public class $!{tableName} {
    /**
     * 服务对象
     */
    @Resource
    private $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;
    
    /**
     * 全查询
     *
     * @param $!{tool.firstLowerCase($tableInfo.name)} 筛选条件
     * @return 查询结果
     */
    @GetMapping
    public R queryAll($!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
            return this.$!{tool.firstLowerCase($tableInfo.name)}Service.queryAll($!{tool.firstLowerCase($tableInfo.name)});
            }
    
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public R queryById(@PathVariable("id") $!pk.shortType id) {
            return this.$!{tool.firstLowerCase($tableInfo.name)}Service.queryById(id);
            }
    
    /**
     * 新增数据
     *
     * @param $!{tool.firstLowerCase($tableInfo.name)} 实体
     * @return 新增结果
     */
    @PostMapping
    public R add(@RequestBody $!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
            return this.$!{tool.firstLowerCase($tableInfo.name)}Service.insert($!{tool.firstLowerCase($tableInfo.name)});
            }
    
    /**
     * 编辑数据
     *
     * @param $!{tool.firstLowerCase($tableInfo.name)} 实体
     * @return 编辑结果
     */
    @PutMapping
    public R edit(@RequestBody $!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
            return this.$!{tool.firstLowerCase($tableInfo.name)}Service.update($!{tool.firstLowerCase($tableInfo.name)});
            }
    
    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public R deleteById($!pk.shortType id) {
            return this.$!{tool.firstLowerCase($tableInfo.name)}Service.deleteById(id);
            }
    
            }
    
    
    • 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
    • 88
    • 89
    • 90
    • 91

    r.java.vm

    ##设置回调
    $!callback.setFileName($tool.append("R.java"))
    $!callback.setSavePath($tool.append($tableInfo.savePath, "/util"))
    
    #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}util;
    
    import lombok.Data;
    
    import java.io.Serializable;
    
    /**
     * 统一返回对象R
     *
     * @author $!author
     * @since $!time.currTime()
     */
    @Data
    public class R implements Serializable {
        private static final long serialVersionUID = $!tool.serial();
        private int code;
        private String message;
        private Object data;
    
        /**
         * 设置数据
         *
         * @param data 数据
         * @return R
         */
        public R setData(Object data) {
            this.data = data;
            return this;
        }
    
        /**
         * 操作成功
         *
         * @return R
         */
        public static R ok() {
            R r = new R();
            r.code = 200;
            r.message = "OK";
            return r;
        }
    
        /**
         * 认证授权失败。 包括密钥信息不正确;数字签名错误;授权已超时
         *
         * @return R
         */
        public static R fail() {
            R r = new R();
            r.code = 401;
            r.message = "fail";
            return r;
        }
    
        /**
         * 系统异常
         *
         * @return R
         */
        public static R exp() {
            R r = new R();
            r.code = 500;
            r.message = "exception";
            return r;
        }
    }
    
    
    • 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

    application.yaml.vm

    ##设置回调
    $!callback.setFileName($tool.append("application.yaml"))
    $!callback.setSavePath($tool.append($modulePath, "/src/main/resources"))
    server:
      port: 8080
    
    spring:
      datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        druid:
          # 下面为连接池的补充设置,应用到上面所有数据源中
          # 初始化大小,最小,最大
          initial-size: 15
          min-idle: 8
          max-active: 30
          # 配置获取连接等待超时的时间
          max-wait: 60000
          # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
          time-between-eviction-runs-millis: 60000
          # 配置一个连接在池中最小生存的时间,单位是毫秒
          min-evictable-idle-time-millis: 300000
          # 打开PSCache,并且指定每个连接上PSCache的大小
          pool-prepared-statements: true
          max-pool-prepared-statement-per-connection-size: 60
          validation-query: SELECT 1 FROM DUAL
          stat-view-servlet:
            enabled: true
          url: url
          username: root
          password: root
          driver-class-name: com.mysql.cj.jdbc.Driver
    
    mybatis:
      mapper-locations: classpath:mapper/*.xml
      configuration:
        # call-setters-on-nulls 参数的作用是查询的某一行某一列为null,是否返回
        call-setters-on-nulls: true
        log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    
    • 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

    banner.txt.vm

    ##设置回调
    $!callback.setFileName($tool.append("banner.txt"))
    $!callback.setSavePath($tool.append($modulePath, "/src/main/resources"))
    ${AnsiColor.BRIGHT_YELLOW}
    
    //                          _ooOoo_                               //
    //                         o8888888o                              //
    //                         88" . "88                              //
    //                         (| ^_^ |)                              //
    //                         O\  =  /O                              //
    //                      ____/`---'\____                           //
    //                    .'  \\|     |//  `.                         //
    //                   /  \\|||  :  |||//  \                        //
    //                  /  _||||| -:- |||||-  \                       //
    //                  |   | \\\  -  /// |   |                       //
    //                  | \_|  ''\---/''  |   |                       //
    //                  \  .-\__  `-`  ___/-. /                       //
    //                ___`. .'  /--.--\  `. . ___                     //
    //              ."" '<  `.___\_<|>_/___.'  >'"".                  //
    //            | | :  `- \`.;`\ _ /`;.`/ - ` : | |                 //
    //            \  \ `-.   \_ __\ /__ _/   .-` /  /                 //
    //      ========`-.____`-.___\_____/___.-`____.-'========         //
    //                           `=---='                              //
    //      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        //
    //            佛祖保佑       永不宕机      永无BUG                  //
    
    
    • 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

    全部模板如上!

    追更!

    加入swagger文档,log日志,时间转换,字符校验,更专业的application文件配置,最完美的跨域过滤器。新版的所有vm如下,上面的是一整套,下面的是一整套,不冲突。用上面就不要用下面的,同理。

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    需要的jar包

    		<dependency>
                <groupId>org.mybatis.spring.bootgroupId>
                <artifactId>mybatis-spring-boot-starterartifactId>
                <version>2.2.2version>
            dependency>
            <dependency>
                <groupId>com.alibabagroupId>
                <artifactId>druid-spring-boot-starterartifactId>
                <version>1.2.15version>
            dependency>
            <dependency>
                <groupId>org.hibernate.validatorgroupId>
                <artifactId>hibernate-validatorartifactId>
                <version>8.0.0.Finalversion>
            dependency>
            <dependency>
                <groupId>io.springfoxgroupId>
                <artifactId>springfox-boot-starterartifactId>
                <version>3.0.0version>
            dependency>
            <dependency>
                <groupId>com.mysqlgroupId>
                <artifactId>mysql-connector-jartifactId>
                <scope>runtimescope>
            dependency>
            <dependency>
                <groupId>org.projectlombokgroupId>
                <artifactId>lombokartifactId>
                <optional>trueoptional>
            dependency>
    
    • 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

    accessfilter.java.vm

    ##设置回调
    $!callback.setFileName($tool.append("AccessFilter.java"))
    $!callback.setSavePath($tool.append($tableInfo.savePath, "/config"))
    
    #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}config;
    import lombok.extern.slf4j.Slf4j;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.http.HttpStatus;
    import org.springframework.web.bind.annotation.RequestMethod;
    
    import javax.servlet.*;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.IOException;
    
    /**
     * 提供跨域支持
     *
     * @author $!author
     * @since $!time.currTime()
     */
    @Slf4j
    @Configuration
    public class AccessFilter implements Filter {
        @Override
        public void init(FilterConfig filterConfig) throws ServletException {
    
        }
    
        @Override
        public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
            HttpServletRequest request = (HttpServletRequest) req;
            HttpServletResponse response = (HttpServletResponse) res;
            response.setHeader("Access-Control-Allow-Origin", "*");
            response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
            response.setHeader("Access-Control-Max-Age", "3600");
            response.setHeader("Access-Control-Allow-Headers", "*");
            // 跨域时会首先发送一个option请求,这里我们给option请求直接返回正常状态
            if (request.getMethod().equals(RequestMethod.OPTIONS.name())) {
                response.setStatus(HttpStatus.OK.value());
                return;
            }
            chain.doFilter(req, res);
        }
    
        @Override
        public void destroy() {
    
        }
    }
    
    
    • 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

    application.yaml.vm

    ##设置回调
    $!callback.setFileName($tool.append("application.yaml"))
    $!callback.setSavePath($tool.append($modulePath, "/src/main/resources"))
    spring:
      profiles:
        active: test
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    application-dev.yaml.vm

    ##设置回调
    $!callback.setFileName($tool.append("application-dev.yaml"))
    $!callback.setSavePath($tool.append($modulePath, "/src/main/resources"))
    server:
      port: 8080
    
    swagger:
      enabled: true
    
    spring:
      jackson:
        date-format: yyyy-MM-dd HH:mm:ss
        time-zone: GMT+8
      mvc:
        pathmatch:
          matching-strategy: ant_path_matcher
      datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        druid:
          # 下面为连接池的补充设置,应用到上面所有数据源中
          # 初始化大小,最小,最大
          initial-size: 15
          min-idle: 8
          max-active: 30
          # 配置获取连接等待超时的时间
          max-wait: 60000
          # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
          time-between-eviction-runs-millis: 60000
          # 配置一个连接在池中最小生存的时间,单位是毫秒
          min-evictable-idle-time-millis: 300000
          # 打开PSCache,并且指定每个连接上PSCache的大小
          pool-prepared-statements: true
          max-pool-prepared-statement-per-connection-size: 60
          validation-query: SELECT 1 FROM DUAL
          url: jdbc:mysql://localhost:3306/study_space
          username: root
          password: root
          driver-class-name: com.mysql.cj.jdbc.Driver
    
    mybatis:
      mapper-locations: classpath:mapper/*.xml
      configuration:
        # call-setters-on-nulls 参数的作用是查询的某一行某一列为null,是否返回
        call-setters-on-nulls: true
        log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    
    
    
    • 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

    application-prod.yaml.vm

    ##设置回调
    $!callback.setFileName($tool.append("application-prod.yaml"))
    $!callback.setSavePath($tool.append($modulePath, "/src/main/resources"))
    server:
      port: 8080
    
    swagger:
      enabled: false
    
    spring:
      jackson:
        date-format: yyyy-MM-dd HH:mm:ss
        time-zone: GMT+8
      datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        druid:
          # 下面为连接池的补充设置,应用到上面所有数据源中
          # 初始化大小,最小,最大
          initial-size: 15
          min-idle: 8
          max-active: 30
          # 配置获取连接等待超时的时间
          max-wait: 60000
          # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
          time-between-eviction-runs-millis: 60000
          # 配置一个连接在池中最小生存的时间,单位是毫秒
          min-evictable-idle-time-millis: 300000
          # 打开PSCache,并且指定每个连接上PSCache的大小
          pool-prepared-statements: true
          max-pool-prepared-statement-per-connection-size: 60
          validation-query: SELECT 1 FROM DUAL
          url: jdbc:mysql://localhost:3306/study_space
          username: root
          password: root
          driver-class-name: com.mysql.cj.jdbc.Driver
    
    mybatis:
      mapper-locations: classpath:mapper/*.xml
      configuration:
        # call-setters-on-nulls 参数的作用是查询的某一行某一列为null,是否返回
        call-setters-on-nulls: true
    
    • 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

    application-test.yaml.vm

    ##设置回调
    $!callback.setFileName($tool.append("application-test.yaml"))
    $!callback.setSavePath($tool.append($modulePath, "/src/main/resources"))
    server:
      port: 8080
    
    swagger:
      enabled: true
    
    spring:
      jackson:
        date-format: yyyy-MM-dd HH:mm:ss
        time-zone: GMT+8
      mvc:
        pathmatch:
          matching-strategy: ant_path_matcher
      datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        druid:
          # 下面为连接池的补充设置,应用到上面所有数据源中
          # 初始化大小,最小,最大
          initial-size: 15
          min-idle: 8
          max-active: 30
          # 配置获取连接等待超时的时间
          max-wait: 60000
          # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
          time-between-eviction-runs-millis: 60000
          # 配置一个连接在池中最小生存的时间,单位是毫秒
          min-evictable-idle-time-millis: 300000
          # 打开PSCache,并且指定每个连接上PSCache的大小
          pool-prepared-statements: true
          max-pool-prepared-statement-per-connection-size: 60
          validation-query: SELECT 1 FROM DUAL
          url: jdbc:mysql://localhost:3306/study_space
          username: root
          password: root
          driver-class-name: com.mysql.cj.jdbc.Driver
    
    mybatis:
      mapper-locations: classpath:mapper/*.xml
      configuration:
        # call-setters-on-nulls 参数的作用是查询的某一行某一列为null,是否返回
        call-setters-on-nulls: true
        log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    
    
    
    • 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

    banner.txt.vm

    ##设置回调
    $!callback.setFileName($tool.append("banner.txt"))
    $!callback.setSavePath($tool.append($modulePath, "/src/main/resources"))
    ${AnsiColor.BRIGHT_YELLOW}
    
    //                          _ooOoo_                               //
    //                         o8888888o                              //
    //                         88" . "88                              //
    //                         (| ^_^ |)                              //
    //                         O\  =  /O                              //
    //                      ____/`---'\____                           //
    //                    .'  \\|     |//  `.                         //
    //                   /  \\|||  :  |||//  \                        //
    //                  /  _||||| -:- |||||-  \                       //
    //                  |   | \\\  -  /// |   |                       //
    //                  | \_|  ''\---/''  |   |                       //
    //                  \  .-\__  `-`  ___/-. /                       //
    //                ___`. .'  /--.--\  `. . ___                     //
    //              ."" '<  `.___\_<|>_/___.'  >'"".                  //
    //            | | :  `- \`.;`\ _ /`;.`/ - ` : | |                 //
    //            \  \ `-.   \_ __\ /__ _/   .-` /  /                 //
    //      ========`-.____`-.___\_____/___.-`____.-'========         //
    //                           `=---='                              //
    //      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        //
    //            佛祖保佑       永不宕机      永无BUG                  //
    
    
    
    • 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

    controller.java.vm

    ##定义初始变量
    #set($tableName = $tool.append($tableInfo.name, "Controller"))
    ##设置回调
    $!callback.setFileName($tool.append($tableName, ".java"))
    $!callback.setSavePath($tool.append($tableInfo.savePath, "/mvc/controller"))
    ##拿到主键
    #if(!$tableInfo.pkColumn.isEmpty())
        #set($pk = $tableInfo.pkColumn.get(0))
    #end
    
    #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}mvc.controller;
    import io.swagger.annotations.Api;
    import io.swagger.annotations.ApiOperation;
    import io.swagger.annotations.ApiParam;
    import lombok.extern.slf4j.Slf4j;
    import $!{tableInfo.savePackageName}.mvc.domain.$!{tableInfo.name};
    import $!{tableInfo.savePackageName}.mvc.service.$!{tableInfo.name}Service;
    import $!{tableInfo.savePackageName}.util.R;
    import org.springframework.web.bind.annotation.*;
    
    import javax.annotation.Resource;
    
    /**
     * $!{tableInfo.comment}($!{tableInfo.name})表控制层
     *
     * @author $!author
     * @since $!time.currTime()
     */
    @Slf4j
    @RestController
    @RequestMapping("$!tool.firstLowerCase($tableInfo.name)")
    @Api(tags = "$!{tableInfo.comment}($!{tableInfo.name})表控制层")
    public class $!{tableName} {
    /**
     * 服务对象
     */
    @Resource
    private $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;
    
    /**
     * 全查询
     *
     * @param $!{tool.firstLowerCase($tableInfo.name)} 筛选条件
     * @return 查询结果
     */
    @ApiOperation("全查询")
    @GetMapping
    public R queryAll(@ApiParam(value = "$!{tool.firstLowerCase($tableInfo.name)} 筛选条件") $!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
            return this.$!{tool.firstLowerCase($tableInfo.name)}Service.queryAll($!{tool.firstLowerCase($tableInfo.name)});
            }
    
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("通过主键查询单条数据")
    @GetMapping("{id}")
    public R queryById(@ApiParam(value = "id 主键") @PathVariable("id") $!pk.shortType id) {
            return this.$!{tool.firstLowerCase($tableInfo.name)}Service.queryById(id);
            }
    
    /**
     * 新增数据
     *
     * @param $!{tool.firstLowerCase($tableInfo.name)} 实体
     * @return 新增结果
     */
    @ApiOperation("新增数据")
    @PostMapping
    public R add(@ApiParam(value = "$!{tool.firstLowerCase($tableInfo.name)} 实体") @RequestBody $!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
            return this.$!{tool.firstLowerCase($tableInfo.name)}Service.insert($!{tool.firstLowerCase($tableInfo.name)});
            }
    
    /**
     * 编辑数据
     *
     * @param $!{tool.firstLowerCase($tableInfo.name)} 实体
     * @return 编辑结果
     */
    @ApiOperation("编辑数据")
    @PutMapping
    public R edit(@ApiParam(value = "$!{tool.firstLowerCase($tableInfo.name)} 实体") @RequestBody $!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
            return this.$!{tool.firstLowerCase($tableInfo.name)}Service.update($!{tool.firstLowerCase($tableInfo.name)});
            }
    
    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @ApiOperation("删除数据")
    @DeleteMapping
    public R deleteById(@ApiParam(value = "id 主键") $!pk.shortType id) {
            return this.$!{tool.firstLowerCase($tableInfo.name)}Service.deleteById(id);
            }
    
            }
    
    
    • 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
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101

    domain.java.vm

    ##引入宏定义
    $!{define.vm}
    
    ##使用宏定义设置回调(保存位置与文件后缀)
    #save("/mvc/domain", ".java")
    
    #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}mvc.domain;
    
    import lombok.extern.slf4j.Slf4j;
    import io.swagger.annotations.ApiModel;
    import io.swagger.annotations.ApiModelProperty;
    import lombok.AllArgsConstructor;
    import lombok.Data;
    import lombok.NoArgsConstructor;
    
    import java.io.Serializable;
    
    ##使用宏定义实现类注释信息
    #tableComment("实体类")
    @Slf4j
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @ApiModel("$!{tableInfo.comment}($!{tableInfo.name})实体类")
    public class $!{tableInfo.name} implements Serializable {
    private static final long serialVersionUID = $!tool.serial();
    #foreach($column in $tableInfo.fullColumn)
    #if(${column.comment})/**${column.comment}*/#end
    @ApiModelProperty(value = "#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
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33

    logback.xml.vm

    ##设置回调
    $!callback.setFileName($tool.append("logback.xml"))
    $!callback.setSavePath($tool.append($modulePath, "/src/main/resources"))
    
    <configuration>
        <contextName>logbackcontextName>
        
        <property name="LOG_HOME" value="$modulePath/tmp/logs" />
    
        <appender name="console"  class="ch.qos.logback.core.ConsoleAppender">
            <encoder>
                <pattern>%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%npattern>
            encoder>
        appender>
    
        
        <appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <FileNamePattern>${LOG_HOME}/error/%d{yyyy-MM-dd}-error.logFileNamePattern>
                
                <MaxHistory>10MaxHistory>
            rollingPolicy>
            
            <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
                
                <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{30} - %msg%npattern>
            encoder>
            
            <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
                <MaxFileSize>10MBMaxFileSize>
            triggeringPolicy>
            <filter class="ch.qos.logback.classic.filter.LevelFilter">
                <level>ERRORlevel>
                <onMatch>ACCEPTonMatch>
                <onMismatch>DENYonMismatch>
            filter>
    
        appender>
    
        
        <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <FileNamePattern>${LOG_HOME}/%d{yyyy-MM-dd}.logFileNamePattern>
                
                <MaxHistory>10MaxHistory>
            rollingPolicy>
            <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
                
                <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{30} - %msg%npattern>
            encoder>
            
            <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
                <MaxFileSize>10MBMaxFileSize>
            triggeringPolicy>
        appender>
    
        <root level="info">
            <appender-ref ref="console"/>
            <appender-ref ref="file"/>
            <appender-ref ref="error"/>
        root>
    configuration>
    
    • 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

    mapper.java.vm

    ##定义初始变量
    #set($tableName = $tool.append($tableInfo.name, "Mapper"))
    ##设置回调
    $!callback.setFileName($tool.append($tableName, ".java"))
    $!callback.setSavePath($tool.append($tableInfo.savePath, "/mvc/mapper"))
    
    ##拿到主键
    #if(!$tableInfo.pkColumn.isEmpty())
        #set($pk = $tableInfo.pkColumn.get(0))
    #end
    
    #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}mvc.mapper;
    
    import $!{tableInfo.savePackageName}.mvc.domain.$!{tableInfo.name};
    import org.apache.ibatis.annotations.Mapper;
    import org.apache.ibatis.annotations.Param;
    
    import java.util.List;
    
    /**
     * $!{tableInfo.comment}($!{tableInfo.name})表数据库访问层
     *
     * @author $!author
     * @since $!time.currTime()
     */
    @Mapper
    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 总行数
             */
            long count($!{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
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95

    mapper.xml.vm

    ##引入mybatis支持
    $!{mybatisSupport.vm}
    
    ##设置保存名称与保存位置
    $!callback.setFileName($tool.append($!{tableInfo.name}, "Mapper.xml"))
    $!callback.setSavePath($tool.append($modulePath, "/src/main/resources/mapper"))
    
    ##拿到主键
    #if(!$tableInfo.pkColumn.isEmpty())
        #set($pk = $tableInfo.pkColumn.get(0))
    #end
    
    
    DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="$!{tableInfo.savePackageName}.mvc.mapper.$!{tableInfo.name}Mapper">
    
        <resultMap type="$!{tableInfo.savePackageName}.mvc.domain.$!{tableInfo.name}" id="$!{tableInfo.name}Map">
    #foreach($column in $tableInfo.fullColumn)
            <result property="$!column.name" column="$!column.obj.name" jdbcType="$!column.ext.jdbcType"/>
    #end
        resultMap>
    
        
        <select id="queryById" resultMap="$!{tableInfo.name}Map">
            select
              #allSqlColumn()
    
            from $!tableInfo.obj.name
            where $!pk.obj.name = #{$!pk.name}
        select>
    
        
        <select id="queryAll" resultMap="$!{tableInfo.name}Map">
            select
              #allSqlColumn()
    
            from $!tableInfo.obj.name
            <where>
    #foreach($column in $tableInfo.fullColumn)
                <if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
                    and $!column.obj.name = #{$!column.name}
                if>
    #end
            where>
        select>
    
        
        <select id="count" resultType="java.lang.Long">
            select count(*)
            from $!tableInfo.obj.name
            <where>
    #foreach($column in $tableInfo.fullColumn)
                <if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
                    and $!column.obj.name = #{$!column.name}
                if>
    #end
            where>
        select>
    
        
        <insert id="insert" keyProperty="$!pk.name" useGeneratedKeys="true">
            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" keyProperty="$!pk.name" useGeneratedKeys="true">
            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" keyProperty="$!pk.name" useGeneratedKeys="true">
            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
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106

    r.java.vm

    ##设置回调
    $!callback.setFileName($tool.append("R.java"))
    $!callback.setSavePath($tool.append($tableInfo.savePath, "/util"))
    
    #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}util;
    import lombok.extern.slf4j.Slf4j;
    import io.swagger.annotations.ApiModel;
    import io.swagger.annotations.ApiModelProperty;
    import lombok.Data;
    
    import java.io.Serializable;
    
    /**
     * 统一返回对象R
     *
     * @author $!author
     * @since $!time.currTime()
     */
    @Slf4j
    @Data
    @ApiModel("统一返回对象R")
    public class R implements Serializable {
        private static final long serialVersionUID = $!tool.serial();
        @ApiModelProperty(value = "响应编码")
        private int code;
        @ApiModelProperty(value = "响应信息")
        private String message;
        @ApiModelProperty(value = "响应数据")
        private Object data;
    
        /**
         * 设置数据
         *
         * @param data 数据
         * @return R
         */
        public R setData(Object data) {
            this.data = data;
            return this;
        }
    
        /**
         * 操作成功
         *
         * @return R
         */
        public static R ok() {
            R r = new R();
            r.code = 200;
            r.message = "OK";
            return r;
        }
    
        /**
         * 认证授权失败。 包括密钥信息不正确;数字签名错误;授权已超时
         *
         * @return R
         */
        public static R fail() {
            R r = new R();
            r.code = 401;
            r.message = "fail";
            return r;
        }
    
        /**
         * 系统异常
         *
         * @return R
         */
        public static R exp() {
            R r = new R();
            r.code = 500;
            r.message = "exception";
            return r;
        }
    }
    
    
    • 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

    service.java.vm

    ##定义初始变量
    #set($tableName = $tool.append($tableInfo.name, "Service"))
    ##设置回调
    $!callback.setFileName($tool.append($tableName, ".java"))
    $!callback.setSavePath($tool.append($tableInfo.savePath, "/mvc/service"))
    
    ##拿到主键
    #if(!$tableInfo.pkColumn.isEmpty())
        #set($pk = $tableInfo.pkColumn.get(0))
    #end
    
    #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}mvc.service;
    
    import $!{tableInfo.savePackageName}.mvc.domain.$!{tableInfo.name};
    import $!{tableInfo.savePackageName}.util.R;
    
    /**
     * $!{tableInfo.comment}($!{tableInfo.name})表服务接口
     *
     * @author $!author
     * @since $!time.currTime()
     */
    public interface $!{tableName} {
    
            /**
             * 通过ID查询单条数据
             *
             * @param $!pk.name 主键
             * @return 实例对象
             */
            R queryById($!pk.shortType $!pk.name);
    
            /**
             * 全查询
             *
             * @param $!tool.firstLowerCase($!{tableInfo.name}) 筛选条件
             * @return 查询结果
             */
            R queryAll($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
    
            /**
             * 新增数据
             *
             * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
             * @return 实例对象
             */
            R insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
    
            /**
             * 修改数据
             *
             * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
             * @return 实例对象
             */
            R update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
    
            /**
             * 通过主键删除数据
             *
             * @param $!pk.name 主键
             * @return 是否成功
             */
            R 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

    serviceimpl.java.vm

    ##定义初始变量
    #set($tableName = $tool.append($tableInfo.name, "ServiceImpl"))
    ##设置回调
    $!callback.setFileName($tool.append($tableName, ".java"))
    $!callback.setSavePath($tool.append($tableInfo.savePath, "/mvc/service/impl"))
    
    ##拿到主键
    #if(!$tableInfo.pkColumn.isEmpty())
        #set($pk = $tableInfo.pkColumn.get(0))
    #end
    
    #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}mvc.service.impl;
    import lombok.extern.slf4j.Slf4j;
    import $!{tableInfo.savePackageName}.mvc.domain.$!{tableInfo.name};
    import $!{tableInfo.savePackageName}.mvc.mapper.$!{tableInfo.name}Mapper;
    import $!{tableInfo.savePackageName}.mvc.service.$!{tableInfo.name}Service;
    import $!{tableInfo.savePackageName}.util.R;
    import org.springframework.stereotype.Service;
    
    import javax.annotation.Resource;
    
    /**
     * $!{tableInfo.comment}($!{tableInfo.name})表服务实现类
     *
     * @author $!author
     * @since $!time.currTime()
     */
    @Slf4j
    @Service("$!tool.firstLowerCase($!{tableInfo.name})Service")
    public class $!{tableName} implements $!{tableInfo.name}Service {
    @Resource
    private $!{tableInfo.name}Mapper $!tool.firstLowerCase($!{tableInfo.name})Mapper;
    
    /**
     * 通过ID查询单条数据
     *
     * @param $!pk.name 主键
     * @return 实例对象
     */
    @Override
    public R queryById($!pk.shortType $!pk.name) {
            return R.ok().setData(this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.queryById($!pk.name));
            }
    
    /**
     * 全查询
     *
     * @param $!{tool.firstLowerCase($tableInfo.name)} 筛选条件
     * @return 查询结果
     */
    @Override
    public R queryAll($!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
            return R.ok().setData(this.$!{tool.firstLowerCase($tableInfo.name)}Mapper.queryAll($!{tool.firstLowerCase($tableInfo.name)}));
            }
    
    /**
     * 新增数据
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
     * @return 实例对象
     */
    @Override
    public R insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
            this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.insert($!tool.firstLowerCase($!{tableInfo.name}));
            return R.ok().setData($!tool.firstLowerCase($!{tableInfo.name}));
            }
    
    /**
     * 修改数据
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
     * @return 实例对象
     */
    @Override
    public R update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
            this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.update($!tool.firstLowerCase($!{tableInfo.name}));
            return R.ok().setData(this.queryById($!{tool.firstLowerCase($!{tableInfo.name})}.get$!tool.firstUpperCase($pk.name)()));
            }
    
    /**
     * 通过主键删除数据
     *
     * @param $!pk.name 主键
     * @return 是否成功
     */
    @Override
    public R deleteById($!pk.shortType $!pk.name) {
            boolean del = this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.deleteById($!pk.name) > 0;
            return R.ok().setData(del);
            }
            }
    
    • 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
    • 88
    • 89
    • 90
    • 91

    swagger.java.vm

    ##设置回调
    $!callback.setFileName($tool.append("SwaggerConfig.java"))
    $!callback.setSavePath($tool.append($tableInfo.savePath, "/config"))
    
    #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}config;
    import lombok.extern.slf4j.Slf4j;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import springfox.documentation.builders.RequestHandlerSelectors;
    import springfox.documentation.oas.annotations.EnableOpenApi;
    import springfox.documentation.service.ApiInfo;
    import springfox.documentation.service.Contact;
    import springfox.documentation.spi.DocumentationType;
    import springfox.documentation.spring.web.plugins.Docket;
    
    import java.util.ArrayList;
    
    /**
     * Swagger配置
     *
     * @author $!author
     * @since $!time.currTime()
     */
    @Slf4j
    @Configuration
    @EnableOpenApi
    public class SwaggerConfig {
        /**
         * 用于读取配置文件 swagger 属性是否开启
         */
        @Value("${swagger.enabled}")
        Boolean swaggerEnabled;
    
        @Bean
        public Docket docket() {
            return new Docket(DocumentationType.OAS_30)
                    .apiInfo(apiInfo())
                    // 是否开启swagger
                    .enable(swaggerEnabled)
                    .select()
                    // 过滤条件,扫描指定路径下的文件
                    .apis(RequestHandlerSelectors.basePackage("#if($tableInfo.savePackageName)$!{tableInfo.savePackageName}.#{end}mvc.controller"))
                    // 指定路径处理,PathSelectors.any()代表不过滤任何路径
                    //.paths(PathSelectors.any())
                    .build();
        }
    
        /**
         * 作者信息
         */
        private ApiInfo apiInfo() {
            Contact contact = new Contact("Peter Cheung", "https://github.com/PerCheung", "13733139823@163.com");
            return new ApiInfo(
                    "Spring Boot 集成 Swagger3 测试",
                    "Spring Boot 集成 Swagger3 测试接口文档",
                    "v1.0",
                    "https://github.com/PerCheung",
                    contact,
                    "Apache 2.0",
                    "https://www.apache.org/licenses/LICENSE-2.0",
                    new ArrayList<>()
            );
        }
    }
    
    • 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

    一键导入的json文件如下,不过老规矩收取1积分,和文章内的模板一模一样,json使用utf-8编码,乱码者请调节idea的默认编码,或者使用转码工具先对json文件转码。>>>下载模板文件


    更新:已在GitHub上开源,链接🔗一堆vm生成器,用来生成各种代码,拥有全局异常处理,pagehelper分页,模糊查询,动态传值排序等等…

  • 相关阅读:
    node.js+vscode安装与配置
    联合投稿其乐融融 抖音共创助你大显身手
    Java 热更新 Groovy 实践及踩坑指南
    Flink快速入门
    2023高频前端面试题-vue
    循环神经网络
    Java 串行接口调用优化
    68.qt quick-qml多级折叠下拉导航菜单 支持动态添加/卸载 支持qml/widget加载等
    【JavaSE】反射
    Hystrix的监控平台
  • 原文地址:https://blog.csdn.net/weixin_43982359/article/details/127930723