当前位置:网站首页>easycode一键生成插件自定义模板
easycode一键生成插件自定义模板
2022-06-12 19:14:00 【菜鸟是大神】
Easycode是idea的一个插件,可以直接对数据的表生成entity,controller,service,dao,mapper,无需任何编码,简单而强大。
官网自带的模板功能所有欠缺,自定义的一个模板。
注意:
1.增,批量增,删,改,单查,筛选查询
2.lombok实现,如果没有lombok自己更改文件或安装lombok
一、dao.java模板
##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Dao"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/dao"))
##拿到主键
#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})表数据库访问层
* @author shenning
* @description
* @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 影响行数
*/
int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 批量新增
*
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象的集合
* @return 影响行数
*/
int batchInsert(List<$!{tableInfo.name}> $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 修改数据
*
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
* @return 影响行数
*/
int updateById($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 通过主键删除数据
*
* @param $!pk.name 主键
* @return 影响行数
*/
int deleteById($!pk.shortType $!pk.name);
}
二、mapper.xml模板
##引入mybatis支持
$!mybatisSupport
##设置保存名称与保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, "Dao.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}.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>
<!-- 基本字段 -->
<sql id="Base_Column_List">
#allSqlColumn()
</sql>
<!--查询单个-->
<select id="queryById" resultMap="$!{tableInfo.name}Map">
select
<include refid="Base_Column_List" />
from $!tableInfo.obj.name
where $!pk.obj.name = #{$!pk.name}
</select>
<!--通过实体作为筛选条件查询-->
<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>
<!--新增所有列-->
<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>
<!-- 批量新增 -->
<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>
<!--通过主键修改数据-->
<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 id="deleteById">
delete from $!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name}
</delete>
</mapper>
三:entity.java模板
##引入宏定义
$!define
##使用宏定义设置回调(保存位置与文件后缀)
#save("/entity", ".java")
##使用宏定义设置包后缀
#setPackageSuffix("entity")
##使用全局变量实现默认包导入
$!autoImport
import java.io.Serializable;
import lombok.*;
##
##使用宏定义实现类注释信息
/**
* $!{tableInfo.comment}($!{tableInfo.name})实体类
* @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
##若没有使用lombok插件,该段不要注释,按照默认的模板
###foreach($column in $tableInfo.fullColumn)
####使用宏定义实现get,set方法
###getSetMethod($column)
###end
}
四:service.java模板
##定义初始变量
#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}.entity.$!{tableInfo.name};
import java.util.List;
import com.github.pagehelper.PageInfo;
/**
* $!{tableInfo.comment}($!{tableInfo.name})表服务接口
* @author shenning
* @description
* @since $!time.currTime()
*/
public interface $!{tableName} {
//通过ID查询
$!{tableInfo.name} queryById($!pk.shortType $!pk.name);
//通过实体作为筛选条件查询
List<$!{tableInfo.name}> queryAll($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
//新增数据
int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
//修改数据
int updateById($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
//通过主键id删除数据
int deleteById($!pk.shortType $!pk.name);
}
五:serivceImpl.java
##定义初始变量
#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}.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})表服务实现类
* @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;
/**
* 通过ID查询单条数据
* @param $!pk.name 主键
* @return 实例对象
*/
@Override
public $!{tableInfo.name} queryById($!pk.shortType $!pk.name) {
return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.queryById($!pk.name);
}
/**
* 查询多条数据
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
* @return 对象列表
*/
@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;
}
/**
* 新增数据
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
* @return 实例对象
*/
@Override
public int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.insert($!tool.firstLowerCase($!{tableInfo.name}));
}
/**
* 修改数据
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
* @return 实例对象
*/
@Override
public int updateById($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.updateById($!tool.firstLowerCase($!{tableInfo.name}));
}
/**
* 通过主键id删除数据
* @param $!pk.name 主键
*/
@Override
public int deleteById($!pk.shortType $!pk.name) {
return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.deleteById($!pk.name);
}
}
六:controller.java模板
##定义初始变量
#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}.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})表控制层
* @author shenning
* @description
* @since $!time.currTime()
*/
@RestController
@RequestMapping("$!tool.firstLowerCase($tableInfo.name)")
public class $!{tableName} {
/**
* $!{tableInfo.comment}服务对象
*/
@Autowired
private $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;
/**
* 通过主键查询单条数据
*/
@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);
}
/**
* 通过查询条件筛选数据
*/
@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;
}
/**
* 新增数据$!{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;
}
/**
* 修改数据$!{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;
}
/**
* 删除数据$!{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;
}
}
边栏推荐
- 六石认知学:大脑的显速与潜速
- China's asset management market demand and future competitive trends outlook report 2022-2028
- Common troubleshooting tools and analysis artifacts are worth collecting
- Leetcode 494. Objectives and
- 原生Servlet - 文件的Upload&Download
- Cookie & session & kaptcha verification code
- uniapp使用阿里图标
- leetcodeSQL:602. Friend application II: who has the most friends
- 合理地配置线程池
- [SQL] MySQL query statement execution sequence analysis
猜你喜欢
![[SQL] MySQL query statement execution sequence analysis](/img/e0/6c55b798b5debfc780fb51498455ab.jpg)
[SQL] MySQL query statement execution sequence analysis

ISCC2022

【图像去噪】基于各向异性滤波实现图像去噪附matlab代码

Kali2022 how to install w3af

Implementation of VGA protocol based on FPGA

In 2021, the global fire pump drive power revenue is about $381million, and it is expected to reach $489.3 million in 2028

Meituan won the first place in fewclue in the small sample learning list! Prompt learning+ self training practice

什么是数据驱动

leetcode:6096. 咒语和药水的成功对数【排序 + 二分】

liunx部署Seata(Nacos版)
随机推荐
Php+flash large file breakpoint continuation function sharing
Liunx deploy Seata (Nacos version)
Jenkins各配置选项介绍原创
How do I create my own appender in log4j- How to create my own Appender in log4j?
ISCC2022
Global and Chinese smart government industry market research and investment risk outlook report 2022-2028
Super heavy! Apache Hudi multimode index optimizes queries up to 30 times
王学岗room+paging3
kali2022如何安装w3af
What are the third-party software testing organizations in Shanghai that share knowledge about software validation testing?
【观察】华为下一代数据中心,为广西低碳高质量发展“添动能”
Leetcode 416. Split equal sum subset
Operational research optimization of meituan intelligent distribution system - Notes
Cookie & session & kaptcha verification code
232-ch579m learning and development Ethernet routine TCP server (project application package, LAN or WAN test)
Jenkins中pipeline对接CMDB接口获取主机列表的发布实践原创
Detailed explanation of yolox network structure
一种灵活注入 Istio Sidecar 的方案探索
Daily blog - micro service permission 12 matters
vc hacon 联合编程 GenImage3Extern WriteImage