springboot-easycode配置文件修改


網上抄的然后不能夠使用,自己又改了該就可以了

entity ##引入宏定義 $
!define ##使用宏定義設置回調(保存位置與文件后綴) #save("/entity", ".java") ##使用宏定義設置包后綴 #setPackageSuffix("entity") ##使用全局變量實現默認包導入 $!autoImport import lombok.Data; #foreach($column in $tableInfo.fullColumn) #if($column.type.equals("java.util.Date")) import com.fasterxml.jackson.annotation.JsonFormat; import org.springframework.format.annotation.DateTimeFormat; #break #end #end /** * $!{tableInfo.comment}($!{tableInfo.name})實體類 * * @author xiaoG * @since $!time.currTime() */ @Data public class $!{tableInfo.name} { #foreach($column in $tableInfo.fullColumn) #if(${column.comment})/** * ${column.comment} */#end #if($column.type.equals("java.util.Date")) @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") #end private $!{tool.getClsNameByFullName($column.type)} $!{column.name}; #end }
dao

##定義初始變量
#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}.entity.$!{tableInfo.name};
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import com.sun.istack.internal.NotNull;
import java.util.List;

@Mapper
public interface $!{tableName} {

    $!{tableInfo.name} getById(@NotNull $!pk.shortType $!pk.name);

    List<$!{tableInfo.name}> listByEntity($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));

    $!{tableInfo.name} getByEntity($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));

    List<$!{tableInfo.name}> listByIds(List<$!pk.shortType> list);

    int insert(@NotNull $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));

    int insertBatch(List<$!{tableInfo.name}> list);

    int update(@NotNull $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));

    int updateByField(@NotNull @Param("where") $!{tableInfo.name} where, @NotNull @Param("set") $!{tableInfo.name} set);

    int updateBatch(List<$!{tableInfo.name}> list);

    int deleteById(@NotNull $!pk.shortType $!pk.name);

    int deleteByEntity(@NotNull $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
  
    int deleteByIds(List<$!pk.shortType> list);
    
    int countAll();
    
    int countByEntity($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
    
}
service


##定義初始變量
#set($tableName = $tool.append("I",$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}.mapper.$!{tableInfo.name}Mapper;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};

import java.util.List;

public interface $!{tableName} {
    
    $!{tableInfo.name}Mapper get$!{tableInfo.name}Mapper();
   
    $!{tableInfo.name} getById($!pk.shortType $!pk.name);

    $!{tableInfo.name} getByEntity($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));

    List<$!{tableInfo.name}> listByEntity($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));

    List<$!{tableInfo.name}> listByIds(List<$!pk.shortType> ids);

    int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));

    int insertBatch(List<$!{tableInfo.name}> list);

    int update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));

    int updateBatch(List<$!{tableInfo.name}> list);

    int deleteById($!pk.shortType $!pk.name);

    int deleteByEntity($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
  
    int deleteByIds(List<$!pk.shortType> list);
    
    int countAll();
    
    int countByEntity($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
}
serviceImpl


##定義初始變量
#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}.mapper.$!{tableInfo.name}Mapper;
import $!{tableInfo.savePackageName}.service.I$!{tableInfo.name}Service;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

@Service
public class $!{tableName} implements I$!{tableInfo.name}Service {

    @Resource(type = $!{tableInfo.name}Mapper.class)
    private $!{tableInfo.name}Mapper $!tool.firstLowerCase($!{tableInfo.name})Mapper;

    @Override
    public $!{tableInfo.name}Mapper get$!{tableInfo.name}Mapper() {
        return $!tool.firstLowerCase($!{tableInfo.name})Mapper;
    }

    @Override
    public $!{tableInfo.name} getById($!pk.shortType $!pk.name) {
        return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.getById($!{pk.name});
    }

    @Override
    public $!{tableInfo.name} getByEntity($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
        return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.getByEntity($!{tool.firstLowerCase($!{tableInfo.name})});
    }

    @Override
    public List<$!{tableInfo.name}> listByEntity($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
        return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.listByEntity($!{tool.firstLowerCase($!{tableInfo.name})});
    }

    @Override
    public List<$!{tableInfo.name}> listByIds(List<$!pk.shortType> ids) {
        return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.listByIds(ids);
    }

    @Override
    public int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
        //Date date = new Date();
        //$!{tool.firstLowerCase($!{tableInfo.name})}.setCreateDatetime(date);
        //$!{tool.firstLowerCase($!{tableInfo.name})}.setUpdateDatetime(date);
        return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.insert($!{tool.firstLowerCase($!{tableInfo.name})});
    }

    @Override
    public int insertBatch(List<$!{tableInfo.name}> list) {
        return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.insertBatch(list);
    }

    @Override
    public int update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
        //$!{tool.firstLowerCase($!{tableInfo.name})}.setUpdateDatetime(new Date());
        return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.update($!{tool.firstLowerCase($!{tableInfo.name})});
    }

    @Override
    public int updateBatch(List<$!{tableInfo.name}> list) {
        return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.updateBatch(list);
    }

    @Override
    public int deleteById($!pk.shortType $!pk.name) {
        return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.deleteById($!pk.name);
    }

    @Override
    public int deleteByEntity($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
        return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.deleteByEntity($!{tool.firstLowerCase($!{tableInfo.name})});
    }
  
    @Override
    public int deleteByIds(List<$!pk.shortType> list) {
        return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.deleteByIds(list);
    }

    @Override
    public int countAll() {
        return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.countAll();
    }
    
    @Override
    public int countByEntity($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
        return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.countByEntity($!tool.firstLowerCase($!{tableInfo.name}));
    }

}
controller


##定義初始變量
#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}.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.service.I$!{tableInfo.name}Service;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

@RestController
@RequestMapping("/$!tool.firstLowerCase($tableInfo.name)")
public class $!{tableName} {
    
    @Autowired
    private I$!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;

    @GetMapping("/get/{$!pk.name}")
    public $!{tableInfo.name} getById(@PathVariable $!pk.shortType $!pk.name) {
        $tableInfo.name $!tool.firstLowerCase($tableInfo.name) = $!{tool.firstLowerCase($tableInfo.name)}Service.getById(id);
        return $!tool.firstLowerCase($tableInfo.name)!=null?$!tool.firstLowerCase($tableInfo.name):new $!{tableInfo.name}();
    }

    @GetMapping("/get")
    public $!{tableInfo.name} getByEntity($tableInfo.name $!tool.firstLowerCase($tableInfo.name)) {
        return $!{tool.firstLowerCase($tableInfo.name)}Service.getByEntity($!{tool.firstLowerCase($!{tableInfo.name})});
    }

    @GetMapping("/list")
    public List<$!{tableInfo.name}> list($tableInfo.name $!tool.firstLowerCase($tableInfo.name)) {
        List<$tableInfo.name> $!{tool.firstLowerCase($tableInfo.name)}List = $!{tool.firstLowerCase($tableInfo.name)}Service.listByEntity($!{tool.firstLowerCase($!{tableInfo.name})});
        return $!{tool.firstLowerCase($tableInfo.name)}List;
    }

    @PostMapping("/insert")
    public $tableInfo.name insert(@RequestBody $tableInfo.name $!tool.firstLowerCase($tableInfo.name)){
        $!{tool.firstLowerCase($tableInfo.name)}Service.insert($!tool.firstLowerCase($tableInfo.name));
        return $!tool.firstLowerCase($tableInfo.name);
    }

    @PutMapping("/update")
    public int update(@RequestBody $tableInfo.name $!tool.firstLowerCase($tableInfo.name)){
        return $!{tool.firstLowerCase($tableInfo.name)}Service.update($!tool.firstLowerCase($tableInfo.name));
    }

    @DeleteMapping("/delete/{$!pk.name}")
    public int deleteOne(@PathVariable $!pk.shortType $!pk.name){
        return $!{tool.firstLowerCase($tableInfo.name)}Service.deleteById($!pk.name);
    }

    @DeleteMapping("/delete")
    public int deleteBatch(@RequestBody List<$!pk.shortType> $!{pk.name}s){
        int result = 0;
        if ($!{pk.name}s!=null&&$!{pk.name}s.size()>0){
            result = $!{tool.firstLowerCase($tableInfo.name)}Service.deleteByIds($!{pk.name}s);
         }
        return result;
    }

}
##引入mybatis支持
$!mybatisSupport

##設置保存名稱與保存位置
$!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

<?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}.mapper.$!{tableInfo.name}Mapper">

    <resultMap type="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}" id="$!{tableInfo.name}ResultMap">
#foreach($column in $tableInfo.fullColumn)
        <result property="$!column.name" column="$!column.obj.name" jdbcType="$!column.ext.jdbcType"/>
#end
    </resultMap>

    <sql id="table_field">
      #allSqlColumn()
      
    </sql>
       
    <!--通過Id查詢單個-->
    <select id="getById" resultMap="$!{tableInfo.name}ResultMap" parameterType="$pk.type">
        select
          <include refid="table_field" />
        from $!tableInfo.obj.name
        where $!pk.obj.name = #{$!pk.name,jdbcType=$!pk.ext.jdbcType}
    </select>


    <!--通過實體不為空的屬性作為篩選條件查詢列表-->
    <select id="listByEntity" resultMap="$!{tableInfo.name}ResultMap" parameterType="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}">
        select
          <include refid="table_field" />
        from $!tableInfo.obj.name
        <where>
#foreach($column in $tableInfo.fullColumn)
            <if test="$!column.name != null">
                and $!column.obj.name = #{$!column.name,jdbcType=$!column.ext.jdbcType}
            </if>
#end
        </where>
    </select>

    <!--通過實體不為空的屬性作為篩選條件查詢單個-->
    <select id="getByEntity" resultMap="$!{tableInfo.name}ResultMap" parameterType="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}">
        select
          <include refid="table_field" />
        from $!tableInfo.obj.name
        <where>
#foreach($column in $tableInfo.fullColumn)
            <if test="$!column.name != null">
                and $!column.obj.name = #{$!column.name,jdbcType=$!column.ext.jdbcType}
            </if>
#end
        </where>
    </select>

    <!--通過Id列表作為篩選條件查詢列表,列表長度不為0-->
    <select id="listByIds" resultMap="$!{tableInfo.name}ResultMap" parameterType="list">
        select
          <include refid="table_field" />
        from $!tableInfo.obj.name
        where $!pk.obj.name in
        <foreach item="item" collection="list" separator="," open="(" close=")" index="index">
            #{item}
        </foreach>
    </select>

    <!--新增實體屬性不為null的列-->
    <insert id="insert" keyProperty="$!pk.name" useGeneratedKeys="true" parameterType="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}">
        insert into $!{tableInfo.obj.name}
        <trim prefix="(" suffix=")" suffixOverrides=",">
#foreach($column in  $tableInfo.fullColumn)
          <if test="$!column.name != null">
             $!column.obj.name,
          </if>
#end          
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
#foreach($column in  $tableInfo.fullColumn)
          <if test="$!column.name != null">
             #{$!column.name,jdbcType=$!column.ext.jdbcType},
          </if>
#end
        </trim>
    </insert>

    <!--批量新增所有列,列表長度不能為0,且列表id統一為null或者統一不為null-->
    <insert id="insertBatch" keyProperty="$!pk.name" useGeneratedKeys="true" parameterType="list">
        insert into $!{tableInfo.obj.name}
         (#foreach($column in $tableInfo.fullColumn)$!{column.obj.name}#if($velocityHasNext), #end#end)
        values
        <foreach item="item" collection="list" separator="," open="" close="" index="index">
         (#foreach($column in $tableInfo.fullColumn)#{item.$!{column.name},jdbcType=$!column.ext.jdbcType}#if($velocityHasNext), #end#end)
        </foreach>
    </insert>

    <!--通過主鍵修改實體屬性不為null的列-->
    <update id="update" parameterType="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}">
        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,jdbcType=$!column.ext.jdbcType},
            </if>
#end
        </set>
        where $!pk.obj.name = #{$!pk.name,jdbcType=$!pk.ext.jdbcType}
    </update>

    <!--通過表字段修改實體屬性不為null的列-->
    <update id="updateByField">
        update $!{tableInfo.obj.name}
        <set>
#foreach($column in $tableInfo.otherColumn)
            <if test="where.$!{column.name} == null and set.$!{column.name} != null#if($column.type.equals("java.lang.String")) and set.$!{column.name} != ''#end">
                $!column.obj.name = #{set.$!{column.name},jdbcType=$!column.ext.jdbcType},
            </if>
#end
        </set>
        <where>
#foreach($column in $tableInfo.fullColumn)
            <if test="where.$!{column.name} != null">
                and $!column.obj.name = #{where.$!{column.name},jdbcType=$!column.ext.jdbcType}
            </if>
#end
        </where>
    </update>

    <!--通過主鍵修改實體列表,列表長度不能為0,注意:當實體屬性為null時,對應的列也會別更新為null-->
    <update id="updateBatch" parameterType="list">
        update $!{tableInfo.obj.name}
        <trim prefix="set" suffixOverrides=",">
#foreach($column in $tableInfo.otherColumn)
            <trim prefix="$!{column.obj.name} = case" suffix="end,">
                 <foreach collection="list" item="item" index="index">
                  when $!pk.obj.name = #{item.$!pk.name} then #{item.$!column.name}
                 </foreach>
            </trim>
#end
        </trim>
        where $!pk.obj.name in
        <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
            #{item.$!pk.name,jdbcType=$!pk.ext.jdbcType}
        </foreach>
    </update>
    
    <!--通過主鍵刪除-->
    <delete id="deleteById" parameterType="$pk.type">
        delete from $!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name,jdbcType=$!pk.ext.jdbcType}
    </delete>

    <!--通過實體非空屬性刪除-->
    <delete id="deleteByEntity" parameterType="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}">
        delete from $!{tableInfo.obj.name}
        <where>
#foreach($column in $tableInfo.otherColumn)
            <if test="$!column.name != null">
                and $!column.obj.name = #{$!column.name,jdbcType=$!column.ext.jdbcType}
            </if>
#end
        </where>
    </delete>
    
    <!--通過主鍵列表刪除,列表長度不能為0-->
    <delete id="deleteByIds" parameterType="list">
        delete from $!{tableInfo.obj.name} where $!pk.obj.name in
        <foreach item="item" collection="list" separator="," open="(" close=")" index="index">
            #{item}
        </foreach>
    </delete>
    
    <select id="countAll" resultType="int">
        select count($!pk.obj.name) from $!{tableInfo.obj.name}
    </select>
    
    <select id="countByEntity" parameterType="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}" resultType="int">
        select count($!pk.obj.name) from $!{tableInfo.obj.name}
        <where>
#foreach($column in $tableInfo.fullColumn)
            <if test="$!column.name != null">
                and $!column.obj.name = #{$!column.name,jdbcType=$!column.ext.jdbcType}
            </if>
#end
        </where>
    </select>
</mapper>

 

 然后就是配置一下

 

application.yml 


# MyBatis
mybatis:
  # 搜索指定包別名
  typeAliasesPackage: com.rjj.**.**.entity
  # 配置mapper的掃描,找到所有的mapper.xml映射文件
  mapperLocations: classpath*:mapper/*Mapper.xml

結果

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM