如何使用MybatisPlus的代码生成器功能?

编程入门 行业动态 更新时间:2024-10-26 04:21:32

<a href=https://www.elefans.com/category/jswz/34/1771452.html style=如何使用MybatisPlus的代码生成器功能?"/>

如何使用MybatisPlus的代码生成器功能?

第一步:导入这两个依赖

<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-generator</artifactId><version>3.5.1</version></dependency><dependency><groupId>org.freemarker</groupId><artifactId>freemarker</artifactId><version>2.3.31</version>
</dependency>

第二步:编写代码自动生成的类

package com.example.mybatisplus.Test;import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;import java.util.Collections;public class FastAutoGeneratorTest {public static void main(String[] args) {FastAutoGenerator.create("jdbc:mysql://127.0.0.1:3306/你的数据库名字?characterEncoding=utf-8&userSSL=false", "root", "你的密码").globalConfig(builder -> {builder.author("aiw") // 设置作者//.enableSwagger() // 开启 swagger 模式.fileOverride() // 覆盖已生成文件.outputDir("E://"); // 指定输出目录}).packageConfig(builder -> {builder.parent("com.example.mybatisplus") // 设置父包名.moduleName("pojo") // 设置父包模块名.pathInfo(Collections.singletonMap(OutputFile.mapperXml, "E://"));// 设置mapperXml生成路径}).strategyConfig(builder -> {builder.addInclude("t_user") // 设置需要生成的表名.addTablePrefix("t_", "c_"); // 设置过滤表前缀}).templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板.execute();}

如下所示生成成功:

我们打开我们设置输出的目录:

打开com目录下的子目录,如下所示:

更多推荐

如何使用MybatisPlus的代码生成器功能?

本文发布于:2023-11-16 18:11:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630688.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   功能   代码生成器   MybatisPlus

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!