当前位置:网站首页>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;
}
}
边栏推荐
- Start with no place to live
- leetcodeSQL:578. Questions with the highest response rate
- Fault analysis | a case of MySQL remote slave database replication delay
- RT thread simulator builds lvgl development and debugging environment
- leetcodeSQL:602. Friend application II: who has the most friends
- 3D object detection
- Leetcode 474. One and zero
- What did 3GPP ran do in the first F2F meeting?
- PHP converts total seconds to hours, minutes and seconds
- 王学岗room+paging3
猜你喜欢
![[SQL] MySQL query statement execution sequence analysis](/img/e0/6c55b798b5debfc780fb51498455ab.jpg)
[SQL] MySQL query statement execution sequence analysis

Business opportunities with an annual increase of 3billion - non cage eggs or a new blue ocean for export to ASEAN

数据库全量SQL分析与审计系统性能优化之旅

什么是数据驱动

I was badly hurt by the eight part essay...

On how to make digital transformation after the loan of large policy banks- Yixinhuachen

运算器的基本结构

chrome浏览器解决跨域问题

今晚7:00 | PhD Debate 自监督学习在推荐系统中的应用
![[image denoising] image denoising based on anisotropic filtering with matlab code](/img/3d/ee2e36b15b5db2502e43f6945685c5.png)
[image denoising] image denoising based on anisotropic filtering with matlab code
随机推荐
leetcode:6097. Match [set record + query one by one with the same length] after replacing characters
unity websockt一些知识:
Wangxuegang room+paging3
leetcode:5270. Minimum path cost in Grid [simple level DP]
mysql的增删改查,mysql常用命令
RT-Thread 模拟器 simulator 搭建 LVGL 的开发调试环境
【数字IC/FPGA】数据累加输出
META-INF、WEB-INF分别是什么?
CVPR 2022 oral Dalian Institute of technology proposed SCI: a fast and powerful low light image enhancement method
Cookie & session & kaptcha verification code
New product launch
超级重磅!Apache Hudi多模索引对查询优化高达30倍
ISCC2022
Shell arrays and functions
Market scale forecast and future competitive trend outlook report of China's plastic and cosmetic industry 2022-2028
【5GC】三种SSC(Session and Service Continuity)模式介绍
基于微信电子书阅读小程序毕业设计毕设作品(5)任务书
Istio 1.14 发布
选电子工程被劝退,真的没前景了?
Uniapp uses the Ali Icon