Easycode—MybatisPlus模板
EasyCode使用指南
1、下载EasyCode插件

2、配置EasyCode
2.1、配置作者名称

2.2、配置代码内容生成模板(模板内容见文末)

3、连接数据库

4、使用代码内容生成模板


模板内容:
controller.java.vm
##导入宏定义
$!{define.vm} ##设置表后缀(宏定义)
#setTableSuffix("Controller") ##保存文件(宏定义)
#save("/controller", "Controller.java") ##包路径(宏定义)
#setPackageSuffix("controller") ##定义服务名
#set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service")) ##定义实体对象名
#set($entityName = $!tool.firstLowerCase($!tableInfo.name)) import $!{tableInfo.savePackageName}.domain.dto.$!{tableInfo.name}Dto;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.web.bind.annotation.*; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo; import java.util.List;
import lombok.RequiredArgsConstructor; ##表注释(宏定义)
#tableComment("表控制层")
@RestController
@RequestMapping("$!tool.firstLowerCase($!tableInfo.name)")
@RequiredArgsConstructor
public class $!{tableName} extends BaseController{
/**
* 服务对象
*/
private final $!{tableInfo.name}Service $!{serviceName}; /**
*
* @param $!{entityName}dto 请求参数封装
* @author $!author
* @description //TODO 分页查询所有数据
* @date $!time.currTime()
* @return 实例对象
*/
@PostMapping("/get$!{tableInfo.name}s")
public TableDataInfo find$!{tableInfo.name}SelectList(@RequestBody $!{tableInfo.name}Dto $!{entityName}dto ) {
startPage();
return getDataTable(this.$!{serviceName}.find$!{tableInfo.name}SelectList($!{entityName}dto));
} /**
*
* @param $!{entityName}dto 请求参数封装
* @author $!author
* @description //TODO 通过主键查询单条数据
* @date $!time.currTime()
* @return 单条数据
*/
@PostMapping("/get$!{tableInfo.name}ById")
public AjaxResult select$!{tableInfo.name}ById(@RequestBody $!{tableInfo.name}Dto $!{entityName}dto) {
return AjaxResult.success($!{serviceName}.select$!{tableInfo.name}ById($!{entityName}dto.getId()));
} /**
*
* @param $!{entityName}dto 实体对象
* @author $!author
* @description //TODO 新增数据
* @date $!time.currTime()
* @return 新增结果
*/
@PostMapping("/add$!{tableInfo.name}")
public AjaxResult add$!{tableInfo.name}(@RequestBody $!{tableInfo.name}Dto $!{entityName}dto) {
return toAjax(this.$!{serviceName}.insert($!{entityName}dto));
} /**
*
* @param $!{entityName}dto 实体对象
* @author $!author
* @description //TODO 修改数据
* @date $!time.currTime()
* @return 修改结果
*/
@PostMapping("/update$!{tableInfo.name}")
public AjaxResult update(@RequestBody $!{tableInfo.name}Dto $!{entityName}dto) {
return toAjax(this.$!{serviceName}.update($!{entityName}dto));
} /**
*
* @param ids 主键集合
* @author $!author
* @description //TODO 删除数据
* @date $!time.currTime()
* @return 删除结果
*/
@PostMapping("/delete$!{tableInfo.name}")
public AjaxResult delete(@RequestParam("ids") List<Long> ids) {
return toAjax(this.$!{serviceName}.deleteById(ids));
}
}
dto.java.vm
##引入宏定义
$!{define.vm} ##使用宏定义设置回调(保存位置与文件后缀)
#save("/domain/dto", ".java") ##使用宏定义设置包后缀
#setPackageSuffix("domain.dto") ##使用全局变量实现默认包导入
$!{autoImport.vm}
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode; import java.util.List; ##使用宏定义实现类注释信息
#tableComment("实体类")
@Data
public class $!{tableInfo.name}Dto { #foreach($column in $tableInfo.fullColumn)
#if(${column.comment})/**
* ${column.comment}
*/#end private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end List<Long> ids;
/**
* 页
*/
private Integer pageNum;
/**
* 条
*/
private Integer pageSize;
/**
* 开始时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime startTime;
/**
* 结束时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime endTime; public Integer getPageNum() {
return pageNum == null ? 1 : pageNum;
} public Integer getPageSize() {
return pageSize == null ? 10 : pageSize;
}
}
mapper.java.vm
##导入宏定义
$!{define.vm} ##设置表后缀(宏定义)
#setTableSuffix("Mapper") ##保存文件(宏定义)
#save("/mapper", "Mapper.java") ##包路径(宏定义)
#setPackageSuffix("mapper") import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import $!{tableInfo.savePackageName}.domain.pojo.$!tableInfo.name;
import org.apache.ibatis.annotations.Mapper; import java.util.List; ##表注释(宏定义)
#tableComment("表数据库访问层")
@Mapper
public interface $!{tableName} extends BaseMapper<$!tableInfo.name> { /**
*
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
* @author $!author
* @description 分页查询数据
* @date $!time.currTime()
* @return 实例对象
*/
List<$!{tableInfo.name}> select$!{tableInfo.name}List($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
}
mapper.xml.vm
##引入mybatis支持
$!{mybatisSupport.vm} ##设置保存名称与保存位置
$!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}.domain.pojo.$!{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> <!--查询指定行数据-->
<select id="select$!{tableInfo.name}List" resultMap="$!{tableInfo.name}Map">
select
#allSqlColumn() 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>
</mapper>
pojo.java.vm
##引入宏定义
$!{define.vm} ##使用宏定义设置回调(保存位置与文件后缀)
#save("/domain/pojo", ".java") ##使用宏定义设置包后缀
#setPackageSuffix("domain.pojo") ##使用全局变量实现默认包导入
$!{autoImport.vm}
import java.io.Serializable;
import lombok.Data; ##使用宏定义实现类注释信息
#tableComment("实体类")
@Data
public class $!{tableInfo.name} { 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};
#end }
service.java.vm
##导入宏定义
$!{define.vm} ##设置表后缀(宏定义)
#setTableSuffix("Service") ##保存文件(宏定义)
#save("/service", "Service.java") ##包路径(宏定义)
#setPackageSuffix("service") import com.baomidou.mybatisplus.extension.service.IService;
import $!{tableInfo.savePackageName}.domain.dto.$!tableInfo.nameDto;
import $!{tableInfo.savePackageName}.domain.pojo.$!tableInfo.name;
import java.util.List; ##表注释(宏定义)
#tableComment("表服务接口")
public interface $!{tableName} extends IService<$!tableInfo.name> { /**
*
* @param id 主键
* @author $!author
* @description 通过ID查询单条数据
* @date $!time.currTime()
* @return 实例对象
*/
public $!{tableInfo.name} select$!{tableInfo.name}ById (Long id); /**
*
* @param $!tool.firstLowerCase($!{tableInfo.name})dto 实例对象
* @author $!author
* @description 分页查询数据
* @date $!time.currTime()
* @return 实例对象
*/
public List<$!{tableInfo.name}> find$!{tableInfo.name}SelectList ($!{tableInfo.name}Dto $!tool.firstLowerCase($!{tableInfo.name})dto); /**
*
* @param $!tool.firstLowerCase($!{tableInfo.name})dto 实例对象
* @author $!author
* @description 新增数据
* @date $!time.currTime()
* @return 实例对象
*/
public int insert($!{tableInfo.name}Dto $!tool.firstLowerCase($!{tableInfo.name})dto); /**
*
* @param $!tool.firstLowerCase($!{tableInfo.name})dto 实例对象
* @author $!author
* @description 修改数据并返回
* @date $!time.currTime()
* @return 实例对象
*/
public int update($!{tableInfo.name}Dto $!tool.firstLowerCase($!{tableInfo.name})dto); /**
*
* @param ids 主键
* @author $!author
* @description 通过主键删除数据
* @date $!time.currTime()
* @return
*/
public int deleteById(List<Long> ids);
}
serviceImpl.java.vm
##导入宏定义
$!{define.vm} ##设置表后缀(宏定义)
#setTableSuffix("ServiceImpl") ##保存文件(宏定义)
#save("/service/impl", "ServiceImpl.java") ##包路径(宏定义)
#setPackageSuffix("service.impl") import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper;
import $!{tableInfo.savePackageName}.domain.pojo.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.domain.dto.$!{tableInfo.name}Dto;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.stereotype.Service;
import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper; import java.util.List;
import lombok.RequiredArgsConstructor; import com.ruoyi.common.utils.bean.BeanUtils; ##表注释(宏定义)
#tableComment("表服务实现类")
@Service("$!tool.firstLowerCase($tableInfo.name)Service")
@RequiredArgsConstructor
public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Dao, $!{tableInfo.name}> implements $!{tableInfo.name}Service { private final $!{tableInfo.name}Mapper $!tool.firstLowerCase($!{tableInfo.name})Mapper;
/**
*
* @param id 主键
* @author $!author
* @description //TODO 通过ID查询单条数据
* @date $!time.currTime()
* @return 实例对象
*/
@Override
public $!{tableInfo.name} select$!{tableInfo.name}ById (Long id) {
LambdaQueryWrapper<$!{tableInfo.name}> $!{tool.firstLowerCase($!{tableInfo.name})}lam = new LambdaQueryWrapper<$!{tableInfo.name}>();
$!{tool.firstLowerCase($!{tableInfo.name})}lam.eq($!{tableInfo.name} ::getId ,id);
return baseMapper.selectOne($!{tool.firstLowerCase($!{tableInfo.name})}lam);
} /**
*
* @param $!tool.firstLowerCase($!{tableInfo.name})dto 实例对象
* @author $!author
* @description //TODO 分页查询数据
* @date $!time.currTime()
* @return 实例对象
*/
@Override
public List<$!{tableInfo.name}> find$!{tableInfo.name}SelectList ($!{tableInfo.name}Dto $!tool.firstLowerCase($!{tableInfo.name})dto) {
$!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}) = new $!{tableInfo.name}();
BeanUtils.copyBeanProp($!tool.firstLowerCase($!{tableInfo.name}),$!tool.firstLowerCase($!{tableInfo.name})dto);
return this.$!{tool.firstLowerCase($tableInfo.name)}Mapper.select$!{tableInfo.name}List($!{tool.firstLowerCase($tableInfo.name)});
} /**
*
* @param $!tool.firstLowerCase($!{tableInfo.name})dto 实例对象
* @author $!author
* @description //TODO 新增数据
* @date $!time.currTime()
* @return 实例对象
*/
@Override
public int insert($!{tableInfo.name}Dto $!tool.firstLowerCase($!{tableInfo.name})dto) {
$!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}) = new $!{tableInfo.name}();
BeanUtils.copyBeanProp($!tool.firstLowerCase($!{tableInfo.name}),$!tool.firstLowerCase($!{tableInfo.name})dto);
return baseMapper.insert($!tool.firstLowerCase($!{tableInfo.name}));
} /**
*
* @param $!tool.firstLowerCase($!{tableInfo.name})dto 实例对象
* @author $!author
* @description //TODO 修改数据并返回
* @date $!time.currTime()
* @return 实例对象
*/
@Override
public int update($!{tableInfo.name}Dto $!tool.firstLowerCase($!{tableInfo.name})dto) {
$!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}) = new $!{tableInfo.name}();
BeanUtils.copyBeanProp($!tool.firstLowerCase($!{tableInfo.name}),$!tool.firstLowerCase($!{tableInfo.name})dto);
return baseMapper.updateById($!{tool.firstLowerCase($!{tableInfo.name})});
} /**
*
* @param idList 主键
* @author $!author
* @description //TODO 通过主键删除数据
* @date $!time.currTime()
* @return
*/
@Override
public void deleteById(List<Long> idList) {
return baseMapper.deleteBatchIds(idList);
}
}
Easycode—MybatisPlus模板的更多相关文章
- 基于EasyCode定制Mybatisplus全自动单表实现:新增/批量新增/修改/批量删除/分页查询/ID查询
基于EasyCode定制Mybatisplus全自动单表实现CRUD接口 分页查询 ID查询 新增 批量新增 修改 批量删除 注意使用了MybatisPlus的自动填充功能,和insertBatchS ...
- EasyCode Entity 实体类模板 IDEA
自己修改了一份EasyCode的实体类模板,防止日后找不到在这里存一下 修改了如下内容: 取消生成GetSet方法,改用Lombok 修改默认命名规则,改为[表名Entity.java] 取消了实现序 ...
- mybatis-plus的代码生成器
简介:构建自定义mybatis-plus模板,自动生成mybatis,entity,mapper,service,controller 项目源码:https://github.com/y369q369 ...
- springboot+mybatisplus 测试代码生成
测试springboot + mybatisplus 实现代码生成 使用默认的模板引擎 pom.xml文件 <?xml version="1.0" encoding=&q ...
- EasyCode实现数据库到Swagger全自动化
简介 EasyCode是基于IntelliJ IDEA开发的代码生成插件,通过自定义生成模板可以完成定制化的 Mapper Service Controller 生成,结合数据库 Comment还可以 ...
- 从零开始的SpringBoot项目 ( 六 ) 整合 MybatisPlus 实现代码自动生成
1.添加依赖 <!-- MySQL数据库 --> <dependency> <groupId>mysql</groupId> <artifactI ...
- 还在使用MyBatis Generator?试试这个工具
代码生成 在企业软件开发过程中,大多数时间都是面向数据库表的增删改查开发.通过通用的增删改查代码生成器,可以有效的提高效率,降低成本:把有规则的重复性劳动让机器完成,解放开发人员. MyBatis G ...
- 学习一下 SpringCloud (二)-- 服务注册中心 Eureka、Zookeeper、Consul、Nacos
(1) 相关博文地址: 学习一下 SpringCloud (一)-- 从单体架构到微服务架构.代码拆分(maven 聚合): https://www.cnblogs.com/l-y-h/p/14105 ...
- 手记系列之二 ----- 关于IDEA的一些使用方法经验
前言 本篇文章主要介绍的关于本人在使用IDEA的一些使用方法,一些常用设置,一些插件推荐和使用.请注意,本文特长,2w多字加上几十张图片,建议收藏观看~ 前提准备 idea官网: https://ww ...
- SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 后端篇(一): 搭建基本环境、整合 Swagger、MyBatisPlus、JSR303 以及国际化操作
相关 (1) 相关博文地址: SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 前端篇(一):搭建基本环境:https://www.cnblogs.com/l-y- ...
随机推荐
- css你所不知道技巧
利用属性选择器来选择空链接 当 <a> 元素没有文本内容,但有 href 属性的时候,显示它的 href 属性: a[href^="http"]:empty::befo ...
- Sql Sugar 拾遗
SqlSugar 拾遗 更新操作 //UpdateColumns:只更新某些列 db.Updateable(entity).UpdateColumns(it => new { it.Name } ...
- vue 滑动到指定位置
在Vue中,有三种方式可以实现H5页面滑动至指定位置 方法1: //先获取目标位置距离 mounted() { this.$nextTick(() => { setTimeout(() => ...
- Python条件语句和基本数据类型
1.if基本语句 if 条件: 内部代码块 else: ...... 2.if支持嵌套 if 1 == 1: if 2 == 2: print('走一步') else: print('走两步') el ...
- 借助mapshaper的简化来修复geojson的拓扑错误
在使用turf.union方法合并面的时候,报错了.无法全部合并完成. 按照提示说是出现线的拓扑错误.至于哪里错误也看不出来. turf不提供拓扑修正功能的js包 难道有转到arcgis中去修复?好搓 ...
- csdn 复制
$("#content_views pre").css("user-select","text"); $("#content_vi ...
- @Configuration 配置类打断点后,一启动项目读取到该配置类的话就会进断点
@Configuration 配置类的话,打断点的时候,一启动项目就会读取配置信息,然后你在@Configuration 配置的类中打断点的话,一启动项目就会读取配置类,然后就会进断点,跟你平常的co ...
- 【Java学习Day11】变量种类及命名规范
变量 变量是什么:就是可以变化的量 Java是一种强类型语言,每个变量都必须声明其类型 Java变量是程序中最基本的存储单元,其要素包括变量名,变量类型和作用域 type varName [=valu ...
- pycharm 连接 docker容器
1.ubuntu 18.04 先安装sudo apt-get install openssh-server 2.修改" /etc/ssh/sshd_config" 改成 Permi ...
- C#判断窗体是否打开,并获取聚焦、未打开则新建一个子窗体
在桌面程序开发会遇到的情况,托盘功能或者是小功能弹窗问题: 现有一个主窗体有子窗体 子窗体每个都可以新建其他窗体问题:新建子窗体时怎么判断子窗体是否打开?若子窗体打开则置顶获取焦点.若未打开则新建一个 ...