springboot+mybatisplus逆向工程生成代码

简介: springboot+mybatisplus逆向工程生成代码

1.引入pom依赖

    <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
            <version>3.3.1.tmp</version>
        </dependency>
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity-engine-core</artifactId>
            <version>2.2</version>
        </dependency>

2.Code

package com.wang.mybatisplus;
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.NamingStrategy;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class MybatisPlusGeneratorApplicationTests {
    @Test
    void codeGenerator () {
        // 代码生成器
        AutoGenerator mpg = new AutoGenerator();
        // 1.全局配置
        GlobalConfig gc = new GlobalConfig();
        gc.setActiveRecord(true);//支持AR模式
        String projectPath = System.getProperty("user.dir");
        gc.setOutputDir(projectPath + "/src/main/java");
        gc.setFileOverride(true);//文件覆盖
        gc.setIdType(IdType.AUTO);//主键自增
        gc.setServiceName("%sService");//设置接口名称是否有I
        gc.setAuthor("王一宁");
        gc.setBaseResultMap(true);//xml映射
        gc.setBaseColumnList(true);//sql片段
        mpg.setGlobalConfig(gc);
        // 2.数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://localhost:3306/mp?serverTimezone=UTC&useUnicode=true&useSSL=false&characterEncoding=utf8");
        dsc.setDbType(DbType.MYSQL);
        dsc.setDriverName("com.mysql.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("123456");
        mpg.setDataSource(dsc);
        // 3.策略配置
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setCapitalMode(true);//全局大小写命名
        strategyConfig.setNaming(NamingStrategy.underline_to_camel);
        strategyConfig.setColumnNaming(NamingStrategy.underline_to_camel);
        strategyConfig.setTablePrefix("tbl_");
        strategyConfig.setEntityLombokModel(true);//使用lombok
        strategyConfig.setInclude("tbl_user");//生成使用的表
        // 4.包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent("com.wang.mybatisplus");
        pc.setMapper("mapper");
        pc.setService("service");
        pc.setController("controller");
        pc.setEntity("domain");
        pc.setXml("mapper");
        mpg.setPackageInfo(pc);
        // 5.执行
        mpg.execute();
    }
}


目录
相关文章
|
6天前
|
Java 关系型数据库 数据库连接
MyBatis-Plus整合SpringBoot及使用
务必记住,随着MyBatis-Plus版本的更新,一些具体的配置和使用方式可能会有所变动。在实际开发过程中,建议参考MyBatis-Plus的官方文档,以获取最新和详细的指导。
19 1
|
7天前
|
Java 关系型数据库 数据库连接
MyBatis-Plus整合SpringBoot及使用
务必记住,随着MyBatis-Plus版本的更新,一些具体的配置和使用方式可能会有所变动。在实际开发过程中,建议参考MyBatis-Plus的官方文档,以获取最新和详细的指导。
21 1
|
23天前
|
Java 数据库连接 Maven
文本,使用SpringBoot工程创建一个Mybatis-plus项目,Mybatis-plus在编写数据层接口,用extends BaseMapper<User>继承实体类
文本,使用SpringBoot工程创建一个Mybatis-plus项目,Mybatis-plus在编写数据层接口,用extends BaseMapper<User>继承实体类
|
1月前
|
前端开发 JavaScript 网络协议
Springboot中为什么你能通过一小段代码来访问网页?
Springboot中为什么你能通过一小段代码来访问网页?
29 7
|
1月前
|
Java 数据库连接 数据库
Spring Boot 集成 MyBatis-Plus 总结
Spring Boot 集成 MyBatis-Plus 总结
|
22天前
|
存储 Java
软件开发常用之SpringBoot文件上传接口编写(中),一本书,代码大全(里面有很多代码重构的方法),屎山代码的原因是不断追加逻辑,在错误代码上堆积新的功能,在写完逻辑之后去思考一下,逻辑合理不
软件开发常用之SpringBoot文件上传接口编写(中),一本书,代码大全(里面有很多代码重构的方法),屎山代码的原因是不断追加逻辑,在错误代码上堆积新的功能,在写完逻辑之后去思考一下,逻辑合理不
|
22天前
|
安全 测试技术 数据库
基于SpringBoot+Vue中小企业人事管理系统代码(源码+部署说明+演示视频+源码介绍)(2)
基于SpringBoot+Vue中小企业人事管理系统代码(源码+部署说明+演示视频+源码介绍)
21 0
|
22天前
|
Java 关系型数据库 MySQL
基于SpringBoot+Vue中小企业人事管理系统代码(源码+部署说明+演示视频+源码介绍)(1)
基于SpringBoot+Vue中小企业人事管理系统代码(源码+部署说明+演示视频+源码介绍)
17 0
|
24天前
|
Java 数据库连接 Maven
Private method ‘getVideoList()‘ is never used,mybatis必须指定Mapper文件和实体目录,在参考其他人写的代码,要认真分析别人的代码,不要丢失
Private method ‘getVideoList()‘ is never used,mybatis必须指定Mapper文件和实体目录,在参考其他人写的代码,要认真分析别人的代码,不要丢失
|
26天前
|
消息中间件 Java 数据库连接
理解java的springboot+mybatisplus+dubbo+nacos+kafka这一套技术栈
理解java的springboot+mybatisplus+dubbo+nacos+kafka这一套技术栈
33 0