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模板的更多相关文章

  1. 基于EasyCode定制Mybatisplus全自动单表实现:新增/批量新增/修改/批量删除/分页查询/ID查询

    基于EasyCode定制Mybatisplus全自动单表实现CRUD接口 分页查询 ID查询 新增 批量新增 修改 批量删除 注意使用了MybatisPlus的自动填充功能,和insertBatchS ...

  2. EasyCode Entity 实体类模板 IDEA

    自己修改了一份EasyCode的实体类模板,防止日后找不到在这里存一下 修改了如下内容: 取消生成GetSet方法,改用Lombok 修改默认命名规则,改为[表名Entity.java] 取消了实现序 ...

  3. mybatis-plus的代码生成器

    简介:构建自定义mybatis-plus模板,自动生成mybatis,entity,mapper,service,controller 项目源码:https://github.com/y369q369 ...

  4. springboot+mybatisplus 测试代码生成

    测试springboot + mybatisplus 实现代码生成   使用默认的模板引擎 pom.xml文件 <?xml version="1.0" encoding=&q ...

  5. EasyCode实现数据库到Swagger全自动化

    简介 EasyCode是基于IntelliJ IDEA开发的代码生成插件,通过自定义生成模板可以完成定制化的 Mapper Service Controller 生成,结合数据库 Comment还可以 ...

  6. 从零开始的SpringBoot项目 ( 六 ) 整合 MybatisPlus 实现代码自动生成

    1.添加依赖 <!-- MySQL数据库 --> <dependency> <groupId>mysql</groupId> <artifactI ...

  7. 还在使用MyBatis Generator?试试这个工具

    代码生成 在企业软件开发过程中,大多数时间都是面向数据库表的增删改查开发.通过通用的增删改查代码生成器,可以有效的提高效率,降低成本:把有规则的重复性劳动让机器完成,解放开发人员. MyBatis G ...

  8. 学习一下 SpringCloud (二)-- 服务注册中心 Eureka、Zookeeper、Consul、Nacos

    (1) 相关博文地址: 学习一下 SpringCloud (一)-- 从单体架构到微服务架构.代码拆分(maven 聚合): https://www.cnblogs.com/l-y-h/p/14105 ...

  9. 手记系列之二 ----- 关于IDEA的一些使用方法经验

    前言 本篇文章主要介绍的关于本人在使用IDEA的一些使用方法,一些常用设置,一些插件推荐和使用.请注意,本文特长,2w多字加上几十张图片,建议收藏观看~ 前提准备 idea官网: https://ww ...

  10. SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 后端篇(一): 搭建基本环境、整合 Swagger、MyBatisPlus、JSR303 以及国际化操作

    相关 (1) 相关博文地址: SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 前端篇(一):搭建基本环境:https://www.cnblogs.com/l-y- ...

随机推荐

  1. cdn全栈加速nginx二层代理实现

    1 nginx.conf中添加配置如下: server { listen 5050; location / { proxy_pass http://代理IP:3333; proxy_set_heade ...

  2. 092_Schema获取表字段的方式

    Map<String, Schema.SObjectField> objectFields = Schema.getGlobalDescribe().get('ObjectName').g ...

  3. VUE如何创建一个项目

    1.安装 Vite npm install -g create-vite-app 2.利用 Vite 安装 Vue3.0 项目 create-vite-app projectName 3.安装依赖运行 ...

  4. C++中map用法详解(转)

    Map是c++的一个标准容器,她提供了很好一对一的关系,在一些程序中建立一个map可以起到事半功倍的效果,总结了一些map基本简单实用的操作!1. map最基本的构造函数:   map<stri ...

  5. JDK下载很慢

    方法1.直接百度jdk镜像,搜到华为镜像:https://repo.huaweicloud.com/java/jdk/ 方法2.到官网拷贝下载的url:https://download.oracle. ...

  6. Didn't find class "org.apache.http.ProtocolVersion

    使用volley时报"Didn't find class "org.apache.http.ProtocolVersion" 今天在运行签名好的apk 在android9 ...

  7. SAP S/4HANA Cloud的功能亮点以及大中型企业为何更倾向选择它

    SAP-System Applications and Products,是一家来自德国的大型跨国软件公司,成立于1972年.作为全球企业管理和协同化商务解决方案供应商,世界第三大独立软件供应商和全球 ...

  8. 根据Query的名字查找是那个CLF逻辑中使用

    select cdodefinition.cdoname, CLFeventMap.Name "Method", CLFDefinition.CLFNAME CLF--, CLFS ...

  9. Delphi 新语法:泛型

      这里的新语法一般指Delphi7不支持的语法,高版本中会经常遇到,所以花一点时间学会使用它.泛型是一种特殊的类型.你不用一开始就指明参数的具体类型,而是先定义一个类型变量,在使用的时候再确定参数的 ...

  10. 赤菟V307与Matlab的串口通信

    赤菟V307与Matlab的串口通信 赤菟V307(CH32V307)是一款RISC-V内核的MCU,搭载的是沁恒自研RISC-V内核青稞V4F,最高主频144MHz,支持单精度浮点运算(FPU). ...