Easy Code介绍对于JAVA程序员来说 , 日常工作中就是crud的操作 , 每次都要搭建MVC三层 , 还是很繁琐 , 这里就出现了神器easycode的工具 , 可以快速生成代码 , 并且还可以自定义模板 , 这样来对开发人员来说就减少了很多事情 , 把更多的时间去用在业务上 , 大大提高了效率 。下面就一步一步搭建easycode , 并且使用 。
1、打开IntelliJ IDEA 新建一个maven工程

文章插图
2、选择工程存放目录

文章插图
3、下载安装EasyCode插件
file->settings->plugins 搜索Easy Code

文章插图
搜索到后点击Install 我这里安装过了 安装完成会让你重启IDEA 。
如何判断是否安装成功 file->settings->Other settings 看是否有Easy Code这个选项

文章插图
4、引入Easy Code模板 (可以根据个人情况定制 也可以使用默认的)

文章插图
5、创建数据库 , 数据表

文章插图
6、配置数据源(需要指定数据库名称 , 要生成数据表)点击IDEA右侧的Datbase->点击上方的加号->选择Data Source.->MySQL

文章插图
7、配置数据源

文章插图
注意:连接方式需要采用mysql8的连接方式 , 不然可能连接失败
jdbc:mysql://localhost:3306/table?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=false
8、连接成功如图所示

文章插图
【开发神器EasyCode】9、引入springboot的相关pom.xml依赖
<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>1.3.2</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.38</version></dependency></dependencies>
需要用到mybatis的启动器 , 所以也一起引用10、打开Easy Code插件 选要生成的entity,controller,service , serviceimpl,dao右击表名->Easy Code->Generate Code

文章插图
Module:当前项目模块
package:生成代码存放包的位置
Template:生成的模板
11、勾选All表示生成所有 , 勾选禁止提示 , 防止弹出很多个提示信息 , 点击OK

文章插图
12、生成模板entity.java代码:
##引入宏定义$!define$!init##使用宏定义设置回调(保存位置与文件后缀)#save("/entity", ".java")##使用宏定义设置包后缀#setPackageSuffix("entity")##使用全局变量实现默认包导入$!autoImportimport java.io.Serializable;import lombok.Data;##使用宏定义实现类注释信息#tableComment("实体类")@Datapublic class $!{tableInfo.name} implements Serializable {private static final long serialVersionUID = $!tool.serial();#foreach($column in $tableInfo.fullColumn)#if(${column.comment})/*** ${column.comment}*/#endprivate $!{tool.getClsNameByFullName($column.type)} $!{column.name};#end}
controller接口: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 lombok.extern.slf4j.Slf4j;import com.github.pagehelper.PageInfo;import $!{tableInfo.savePackageName}.response.PageResult;import $!{tableInfo.savePackageName}.response.Result;import $!{tableInfo.savePackageName}.response.StatusCode;import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;import org.springframework.web.bind.annotation.*;import org.springframework.util.CollectionUtils;import javax.annotation.Resource;import java.util.List;import java.util.Objects;/** * $!{tableInfo.comment}($!{tableInfo.name})控制层 * * @author protagonist * @since $!time.currTime() */@RestController@Slf4j@RequestMapping("/$!tool.firstLowerCase($tableInfo.name)")public class $!{tableName} {/*** 服务对象*/@Resourceprivate $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)ServiceImpl;/*** 通过主键查询单条数据** @param $!pk.name 主键* @return 单条数据*/@GetMapping(value = https://www.isolves.com/it/cxkf/yy/JAVA/2021-05-13/"/get/{$!pk.name}")public Result selectOne(@PathVariable("$!pk.name") $!pk.shortType $!pk.name) {$tableInfo.name result = $!{tool.firstLowerCase($tableInfo.name)}ServiceImpl.selectById(id);if(Objects.nonNull(result)){return new Result
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 微信小程序开发之hello world
- 作为Web开发人员应避免的10种CSS做法
- Linux下应用开发基础知识大总结
- 阿里开源的限流神器 Sentinel,轻松搞定接口限流
- 如何成为一名后端开发工程师
- 电商网站开发前期需要准备哪些资料?
- npm简介
- 看了这篇MySQL,开发功力又升级
- 文件太多怎么重命名?只需要1个神器就能搞定
- Python开发者的最强工具PyCharm发布2021最新版