当前位置:网站首页>Introduce two automatic code generators to help improve work efficiency
Introduce two automatic code generators to help improve work efficiency
2022-07-02 06:21:00 【Jiang Xia】
Author platform :
| CSDN:blog.csdn.net/qq_41153943
| Nuggets :juejin.cn/user/651387…
| You know :www.zhihu.com/people/1024…
| GitHub:github.com/JiangXia-10…
This article altogether 1683 word , Expected reading 10 minute
Preface
Compared with the previous springmvc frame , Use springboot Development reduces the work of a large number of configuration files , It can greatly improve the efficiency of development . Use springboot If there is a new interface or method in development, the basic steps are as follows :
1、 Corresponding data of new object entity;
2、 newly added controller;
3、 newly added dao;
4、 newly added service And corresponding impl class .
Add these things repeatedly every time , The work is not difficult , But it's boring , It's also a waste of time . Isn't it delicious to touch fish in this time ?
Recommend two today, which can greatly improve work efficiency ( loaf on a job ) The artifact of : Automatic code generator , Some of the code really doesn't have to be written !
One 、EasyCode
The first recommendation is idea Built-in plug-ins ---->Easy Code.EasyCode Is based on IntelliJ IDEA Developed code generation plug-ins , Support to customize any template (Java,html,js,xml). Any database related code can be generated through custom templates . Support database type and java Type mapping configuration . Support the generation of multiple tables at the same time . Each table has independent configuration information . Completely personalized definition , The rules are set by you . Usually used to generate Entity、Dao、Service、Controller. If you have strong hands-on ability, it can also be used to generate HTML、JS、PHP Etc . In theory, any code related to data can be generated .
Easy Code Is based on Database Tool Development , all Database Tool All supported databases are supported . Common databases are basically supported .
The installation steps are as follows : To iead Of plugins Plug in market , Search for downloads easy code that will do
After installation, you can customize the configuration through the following configuration , The default is usually used :
Then if you need to generate specific code , It needs to be used in conjunction with Database Tool, Many database types are supported here , the mysql:
After the above configuration is completed, select the table that needs to generate relevant codes , choice easycode–>generate code that will do
In this way, all the required code is generated successfully :
That's how to use idea Of easycode Use of code generation plug-ins !
Two 、CodeGenerator
This is a mybatis-plus Code generator for , Directly copy the following code , Just put it in a separate folder in the project , Each time according to specific needs , Modify some relevant parameter values , The specific code and relevant comments are explained as follows :
package com.jiangxia.demo;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import org.junit.Test;
/**
* @author:jiangxia
* @since 2022/04/25
*/
public class CodeGenerator {
@Test
public void run() {
// 1、 Create a code generator
AutoGenerator mpg = new AutoGenerator();
// 2、 Global configuration
GlobalConfig gc = new GlobalConfig();
String projectPath = System.getProperty("user.dir");
gc.setOutputDir(projectPath + "/src/main/java");
gc.setAuthor("testjava");
gc.setOpen(false); // Whether to open Explorer after generation
gc.setFileOverride(false); // Whether the file is overwritten during regeneration
gc.setServiceName("%sService"); // Get rid of Service The initial of the interface I
gc.setIdType(IdType.ID_WORKER); // The primary key strategy
gc.setDateType(DateType.ONLY_DATE);// Defines the date type in the generated entity class
gc.setSwagger2(true);// Turn on Swagger2 Pattern
mpg.setGlobalConfig(gc);
// 3、 Data source configuration
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://localhost:3306/test");
dsc.setDriverName("om.mysql.cj.jdbc.Driver");
dsc.setUsername("jiang");
dsc.setPassword("jiang");
dsc.setDbType(DbType.MYSQL);
mpg.setDataSource(dsc);
// 4、 Package configuration
PackageConfig pc = new PackageConfig();
pc.setModuleName("codedemo"); // Module name
pc.setParent("com.jiangxia.demo");// Which bag
pc.setController("controller");//comtroller
pc.setEntity("entity");//entity
pc.setService("service");//service
pc.setMapper("mapper");//mapper
mpg.setPackageInfo(pc);
// 5、 Policy configuration
StrategyConfig strategy = new StrategyConfig();
strategy.setInclude("user");
strategy.setNaming(NamingStrategy.underline_to_camel);// Naming strategy of database table mapping to entity
strategy.setTablePrefix(pc.getModuleName() + "_"); // Remove the table prefix when generating entities
strategy.setColumnNaming(NamingStrategy.underline_to_camel);// Database table fields are mapped to entity naming policies
strategy.setEntityLombokModel(true); // lombok Model @Accessors(chain = true) setter Chain operation
strategy.setRestControllerStyle(true); //restful api Style controller
strategy.setControllerMappingHyphenStyle(true); //url Middle hump to hyphen
mpg.setStrategy(strategy);
// 6、 perform
mpg.execute();
}
}
The setting of the above code only needs to modify the specific database and corresponding table each time . After executing the above code, the corresponding controller、entity Etc , Reduce a lot of creation work .
summary
The above are two automatic code generation tools , You can choose to use... According to your actual situation and needs , This can greatly reduce the unnecessary workload every time , Improve work efficiency , Finish the work early , Get off work early !
If you find it useful , Just like it and forward it to more friends !
If you have any other useful automatic code generation tools , Welcome to , recommend !
Related to recommend
边栏推荐
- 495. Timo attack
- 网络相关知识(硬件工程师)
- Use of Arduino wire Library
- I/o impressions from readers | prize collection winners list
- 利用NVIDIA GPU将Minecraft场景渲染成真实场景
- In depth understanding of JUC concurrency (I) what is JUC
- Shenji Bailian 3.54-dichotomy of dyeing judgment
- IPv6 experiment and summary
- Codeforces Round #797 (Div. 3) A—E
- Detailed steps of JS foreground parsing of complex JSON data "case: I"
猜你喜欢
浏览器原理思维导图
线性dp(拆分篇)
Let every developer use machine learning technology
Google Go to sea entrepreneurship accelerator registration countdown 3 days, entrepreneurs pass through the guide in advance collection!
Data playback partner rviz+plotjuggler
深入学习JVM底层(五):类加载机制
Support new and old imperial CMS collection and warehousing tutorials
IPv6 experiment and summary
CNN visualization technology -- detailed explanation of cam & grad cam and concise implementation of pytorch
sudo提权
随机推荐
最新CUDA环境配置(Win10 + CUDA 11.6 + VS2019)
Codeforces Round #797 (Div. 3) A—E
CUDA中内置的Vector类型和变量
Invalid operation: Load into table ‘sources_ orderdata‘ failed. Check ‘stl_ load_ errors‘ system table
RestTemplate请求时设置请求头,请求参数,请求体。
Compte à rebours de 3 jours pour l'inscription à l'accélérateur de démarrage Google Sea, Guide de démarrage collecté à l'avance!
Support new and old imperial CMS collection and warehousing tutorials
State machine in BGP
Decryption skills of encrypted compressed files
注解和反射详解以及运用
链表(线性结构)
CUDA中的存储空间修饰符
10 erreurs classiques de MySQL
Format check JS
LeetCode 283. 移动零
Detailed steps of JS foreground parsing of complex JSON data "case: I"
IPv6 experiment and summary
Google Play Academy 组队 PK 赛,正式开赛!
复杂 json数据 js前台解析 详细步骤《案例:一》
LeetCode 90. Subset II