当前位置:网站首页>EASYCODE one click plug-in custom template

EASYCODE one click plug-in custom template

2022-06-12 19:28:00 A rookie is a great God

Easycode yes idea A plug-in for , You can directly generate the data table entity,controller,service,dao,mapper, No coding required , Simple and powerful .

The template function of the official website is lacking , A customized template .

Be careful :

1. increase , Batch increase , Delete , Change , Just check , Filter query

2.lombok Realization , without lombok Change files or install by yourself lombok

One 、dao.java Templates

## Define the initial variable
#set($tableName = $tool.append($tableInfo.name, "Dao"))
## Set callback
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/dao"))
 
## Get the primary key
#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.apache.ibatis.annotations.Mapper;
import java.util.List;
 
/**
 * $!{tableInfo.comment}($!{tableInfo.name}) Table database access layer
 * @author shenning
 * @description 
 * @since $!time.currTime()
 */
@Mapper
public interface $!{tableName} {
 
    /**
     * adopt ID Query single data
     *
     * @param $!pk.name Primary key
     * @return Instance object
     */
    $!{tableInfo.name} queryById($!pk.shortType $!pk.name);
 
   
    /**
     * Query by entity as filter criteria
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name}) Instance object
     * @return The object list
     */
    List<$!{tableInfo.name}> queryAll($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
 
    /**
     * The new data
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name}) Instance object
     * @return Number of rows affected
     */
    int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
 
        /**
     * Batch add
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name}) A collection of instances of objects
     * @return Number of rows affected
     */
    int batchInsert(List<$!{tableInfo.name}> $!tool.firstLowerCase($!{tableInfo.name}));
 
    /**
     * Modifying data
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name}) Instance object
     * @return Number of rows affected
     */
    int updateById($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
 
    /**
     * Delete data through primary key
     *
     * @param $!pk.name Primary key
     * @return Number of rows affected
     */
    int deleteById($!pk.shortType $!pk.name);
 
}
Two 、mapper.xml Templates

## introduce mybatis Support
$!mybatisSupport
 
## Set save name and save location
$!callback.setFileName($tool.append($!{tableInfo.name}, "Dao.xml"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources/mapper"))
 
## Get the primary key
#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 type="$!{tableInfo.savePackageName}.entity.$!{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>
 
    <!-- Basic fields -->
    <sql id="Base_Column_List">
        #allSqlColumn()
        
    </sql>
 
    <!-- Query individual -->
    <select id="queryById" resultMap="$!{tableInfo.name}Map">
        select
          <include refid="Base_Column_List" />
        from $!tableInfo.obj.name
        where $!pk.obj.name = #{$!pk.name}
    </select>
 
    <!-- Query by entity as filter criteria -->
    <select id="queryAll" resultMap="$!{tableInfo.name}Map">
        select
          <include refid="Base_Column_List" />
        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>
 
    <!-- Add all columns -->
    <insert id="insert" keyProperty="$!pk.name" useGeneratedKeys="true">
        insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.fullColumn)$!column.obj.name#if($velocityHasNext), #end#end)
        values (#foreach($column in $tableInfo.fullColumn)#{$!{column.name}}#if($velocityHasNext), #end#end)
    </insert>
 
 
     <!-- Batch add -->
    <insert id="batchInsert">
        insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.fullColumn)$!column.obj.name#if($velocityHasNext), #end#end)
        values 
        <foreach collection="list" item="stu" separator=",">
        (
            #foreach($column in $tableInfo.fullColumn)
            #{stu.$!{column.name}}#if($velocityHasNext), #end#end
            
         )
         </foreach>
    </insert>
 
    <!-- Modify data through primary key -->
    <update id="updateById">
        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... By primary key -->
    <delete id="deleteById">
        delete from $!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name}
    </delete>
 
</mapper>
  3、 ... and :entity.java Templates

## Introduce macro definition
$!define
 
## Use macro definition to set callback ( Save location and file suffix )
#save("/entity", ".java")
 
## Use macro definition to set package suffix
#setPackageSuffix("entity")
 
## Use global variables to implement the default package import
$!autoImport
import java.io.Serializable;
import lombok.*;
##
## Use macro definition to implement class annotation information
/**
 * $!{tableInfo.comment}($!{tableInfo.name}) Entity class
 * @author shenning
 * @description 
 * @since $!time.currTime()
 */
@Getter
@Setter
@ToString
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};
##    private $!{tool.getClsNameByFullName($column.type)} $!{tool.firstUpperCase($column.name)};
#end
 
 
## If not used lombok plug-in unit , Do not comment on this paragraph , Follow the default template
###foreach($column in $tableInfo.fullColumn)
#### Use macro definitions to implement get,set Method
###getSetMethod($column)
###end
 
}
Four :service.java Templates

## Define the initial variable
#set($tableName = $tool.append($tableInfo.name, "Service"))
## Set callback
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/service"))
 
## Get the primary key
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end
 
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service;
 
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import java.util.List;
import com.github.pagehelper.PageInfo;
 
 
 
 /**
 * $!{tableInfo.comment}($!{tableInfo.name}) Table service interface
 * @author shenning
 * @description 
 * @since $!time.currTime()
 */
public interface $!{tableName} {
 
    // adopt ID Inquire about
    $!{tableInfo.name} queryById($!pk.shortType $!pk.name);
 
    // Query by entity as filter criteria
    List<$!{tableInfo.name}> queryAll($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
 
    // The new data
    int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
 
    // Modifying data
    int updateById($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
 
    // Through primary key id Delete data
    int deleteById($!pk.shortType $!pk.name);
 
}
  5、 ... and :serivceImpl.java

## Define the initial variable
#set($tableName = $tool.append($tableInfo.name, "ServiceImpl"))
## Set callback
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/service/impl"))
 
## Get the primary key
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end
 
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service.impl;
 
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.dao.$!{tableInfo.name}Dao;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
 
import javax.annotation.Resource;
import java.util.List;
 
 
 /**
 * $!{tableInfo.comment}($!{tableInfo.name}) Table service implementation class
 * @author shenning
 * @description 
 * @since $!time.currTime()
 */
@Service
@Transactional 
public class $!{tableName} implements $!{tableInfo.name}Service {
    @Autowired
    private $!{tableInfo.name}Dao $!tool.firstLowerCase($!{tableInfo.name})Dao;
 
    /**
     * adopt ID Query single data
     * @param $!pk.name Primary key
     * @return Instance object
     */
    @Override
    public $!{tableInfo.name} queryById($!pk.shortType $!pk.name) {
        return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.queryById($!pk.name);
    }
 
    /**
     * Query multiple data
     * @param $!tool.firstLowerCase($!{tableInfo.name}) Instance object
     * @return The object list
     */
    @Override
    public List<$!{tableInfo.name}> queryAll($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
        //PageHelper.startPage(pageNum,pageSize);
        List<$!{tableInfo.name}> dataList = $!{tool.firstLowerCase($!{tableInfo.name})}Dao.queryAll($!tool.firstLowerCase($!{tableInfo.name}));
        //PageInfo<$!{tableInfo.name}> page = new PageInfo<$!{tableInfo.name}>(dataList);
        return dataList;
    }
 
    /**
     * The new data
     * @param $!tool.firstLowerCase($!{tableInfo.name}) Instance object
     * @return Instance object
     */
    @Override
    public int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
        return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.insert($!tool.firstLowerCase($!{tableInfo.name}));
    }
 
    /**
     * Modifying data
     * @param $!tool.firstLowerCase($!{tableInfo.name}) Instance object
     * @return Instance object
     */
    @Override
    public int updateById($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
        return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.updateById($!tool.firstLowerCase($!{tableInfo.name}));
    }
 
    /**
     * Through primary key id Delete data
     * @param $!pk.name Primary key
     */
    @Override
    public int deleteById($!pk.shortType $!pk.name) {
        return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.deleteById($!pk.name);
    }
}
6、 ... and :controller.java Templates

## Define the initial variable
#set($tableName = $tool.append($tableInfo.name, "Controller"))
## Set callback
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/controller"))
## Get the primary key
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end
 
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import javax.annotation.Resource;
 
/**
 * $!{tableInfo.comment}($!{tableInfo.name}) Table control layer
 * @author shenning
 * @description 
 * @since $!time.currTime()
 */
@RestController
@RequestMapping("$!tool.firstLowerCase($tableInfo.name)")
public class $!{tableName} {
    /**
     * $!{tableInfo.comment} service object
     */
    @Autowired
    private $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;
 
    /**
     * Query single data through primary key
     */
    @GetMapping("get$!tool.firstUpperCase($tableInfo.name)One")
    public $!{tableInfo.name} get$!tool.firstUpperCase($tableInfo.name)One($!pk.shortType id) {
        return $!{tool.firstLowerCase($tableInfo.name)}Service.queryById(id);
    }
    
    /**
     * Filter data by query criteria
     */
    @GetMapping("get$!tool.firstUpperCase($tableInfo.name)List")
    public List<$!{tableInfo.name}> get$!tool.firstUpperCase($tableInfo.name)List($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
         List<$!{tableInfo.name}> getList=$!{tool.firstLowerCase($tableInfo.name)}Service.queryAll($!tool.firstLowerCase($!{tableInfo.name}));
         return getList;
    }
    
    /**
     * The new data $!{tableInfo.comment}
     */
    @PostMapping("add$!tool.firstUpperCase($tableInfo.name)")
    public int add$!tool.firstUpperCase($!{tableInfo.name})(@RequestBody $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
        int addState=$!{tool.firstLowerCase($tableInfo.name)}Service.insert($!tool.firstLowerCase($!{tableInfo.name}));
        return addState;
    }
    
    /**
     * Modifying data $!{tableInfo.comment}
     */
    @GetMapping("update$!tool.firstUpperCase($tableInfo.name)")
    public int update$!tool.firstUpperCase($!{tableInfo.name})(@RequestBody $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
         int updateState=$!{tool.firstLowerCase($tableInfo.name)}Service.updateById($!tool.firstLowerCase($!{tableInfo.name}));
         return updateState;
    }
    
    /**
     * Delete data $!{tableInfo.comment}
     */
    @GetMapping("delete$!tool.firstUpperCase($tableInfo.name)")
    public int delete$!tool.firstUpperCase($!{tableInfo.name})($!pk.shortType id) {
         int deleteState=$!{tool.firstLowerCase($tableInfo.name)}Service.deleteById(id);
         return deleteState;
    }
}

原网站

版权声明
本文为[A rookie is a great God]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206121914455769.html