当前位置:网站首页>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
边栏推荐
猜你喜欢

浏览器原理思维导图

Singleton mode compilation

谷歌出海创业加速器报名倒计时 3 天,创业人闯关指南提前收藏!

Replace Django database with MySQL (attributeerror: 'STR' object has no attribute 'decode')

最新CUDA环境配置(Win10 + CUDA 11.6 + VS2019)

It is said that Kwai will pay for the Tiktok super fast version of the video? How can you miss this opportunity to collect wool?

深入了解JUC并发(二)并发理论

LeetCode 78. subset

Let every developer use machine learning technology

ROS create workspace
随机推荐
Network related knowledge (Hardware Engineer)
On Web server
Don't use the new WP collection. Don't use WordPress collection without update
链表(线性结构)
Google Play Academy 组队 PK 赛,正式开赛!
来自读者们的 I/O 观后感|有奖征集获奖名单
CUDA中的Warp Shuffle
Replace Django database with MySQL (attributeerror: 'STR' object has no attribute 'decode')
Top 10 classic MySQL errors
CUDA中的函数执行空间说明符
LeetCode 47. Full arrangement II
深入学习JVM底层(二):HotSpot虚拟机对象
BGP 路由优选规则和通告原则
Singleton mode compilation
VLAN experiment of switching technology
TensorRT中的循环
Let every developer use machine learning technology
Deep learning classification network -- vggnet
线性dp(拆分篇)
LeetCode 283. Move zero