当前位置:网站首页>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;
}
}
边栏推荐
- leetcode:6094. Company name [group enumeration + cannot repeat set intersection + product Cartesian product (repeat indicates length)]
- 【生成对抗网络学习 其三】BiGAN论文阅读笔记及其原理理解
- PHP converts total seconds to hours, minutes and seconds
- Standard library template learning introduction original
- 【5GC】三种SSC(Session and Service Continuity)模式介绍
- The solution of BiliBili video list name too long and incomplete display
- leetcodeSQL:578. Questions with the highest response rate
- [image denoising] image denoising based on regularization with matlab code
- Software usage of Tencent cloud TDP virt viewer win client
- [5gc] Introduction to three SSC (session and service continuity) modes
猜你喜欢
vc hacon 联合编程 GenImage3Extern WriteImage
Leetcodesql: count the number of students in each major
Redis (XXXII) - using redis as a distributed lock
Have a meal, dry pot, fat intestines + palm treasure!
设备管理-借还模块1
从16页PPT里看懂Jack Dorsey的Web5
VC hacon joint programming genimage3extern writeimage
A journey of database full SQL analysis and audit system performance optimization
Chrome browser solves cross domain problems
[generation confrontation network learning III] reading notes of Bigan paper and its principle understanding
随机推荐
A journey of database full SQL analysis and audit system performance optimization
chrome浏览器解决跨域问题
leetcodeSQL:602. Friend application II: who has the most friends
[matrix theory & graph theory] final exam review mind map
What is data driven
Detailed explanation of yolox network structure
基于微信电子书阅读小程序毕业设计毕设作品(6)开题答辩PPT
存储体系概述
Cookie & session & kaptcha verification code
leetcode:6095. Strong password verifier II [simple simulation + direct false]
leetcode:98. Count the number of subarrays whose score is less than k [double pointers + number of calculated subsets + de duplication]
Standard library template learning introduction original
"As a service", the future has come, starting from the present | new mode of it consumption, FOD billing on demand
Market scale forecast and future competitive trend outlook report of China's plastic and cosmetic industry 2022-2028
A small case with 666 times performance improvement illustrates the importance of using indexes correctly in tidb
Can't understand kotlin source code? Starting with the contracts function~
China's asset management market demand and future competitive trends outlook report 2022-2028
On how to make digital transformation after the loan of large policy banks- Yixinhuachen
Wireshark basic commands
【观察】华为下一代数据中心,为广西低碳高质量发展“添动能”