mybatis plus 代码生成器的使用

1.先引入mybatis plus所需要的依赖

         <!-- mybatis-plus -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.1</version>
        </dependency>

        <!--代码生成器-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
            <version>3.5.2</version>
        </dependency>

        <!--Velocity引擎模板-->
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity-engine-core</artifactId>
            <version>2.3</version>
        </dependency>

2.创建一个类Generator在utils包里,写如下代码

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import java.util.Collections;

public class Generator {
    public static void main(String[] args) {
        generate();
    }
    private static void generate() {
            FastAutoGenerator.create("jdbc:mysql://localhost:3306/test?serverTimezone=GMT%2b8", "root", "123456")
                    .globalConfig(builder -> {
                        builder.author("小白") // 设置作者
//                            .enableSwagger() // 开启 swagger 模式
                                .fileOverride() // 覆盖已生成文件
                                .outputDir("F:\\springboot+vue+projcet\\小白\\springboot\\src\\main\\java"); // 指定输出目录
                    })
                    .packageConfig(builder -> {
                        builder.parent("com.example.springboot") // 设置父包名
                                .moduleName(null) // 设置父包模块名
                                .pathInfo(Collections.singletonMap(OutputFile.xml, "F:\\springboot+vue+projcet\\青戈\\springboot\\src\\main\\resources\\mappe
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MyBatis Plus 代码生成器支持使用 SQLite 数据库,只需要在配置文件中指定相应的 JDBC 驱动和连接信息即可。以下是一份示例配置文件: ``` # 数据源配置 spring.datasource.url=jdbc:sqlite:/path/to/db/file.db spring.datasource.driver-class-name=org.sqlite.JDBC spring.datasource.username= spring.datasource.password= # MyBatis Plus 配置 mybatis-plus.mapper-locations=classpath:mapper/*.xml mybatis-plus.type-aliases-package=com.example.entity mybatis-plus.global-config.id-type=auto mybatis-plus.global-config.db-config.logic-delete-value=1 mybatis-plus.global-config.db-config.logic-not-delete-value=0 # 代码生成器配置 mybatis-plus.generator.global-config.author=yourname mybatis-plus.generator.global-config.output-dir=/path/to/generate/code mybatis-plus.generator.global-config.file-override=true mybatis-plus.generator.global-config.enable-cache=false mybatis-plus.generator.strategy.super-entity-class=yourpackage.BaseEntity mybatis-plus.generator.strategy.super-service-class=yourpackage.BaseService mybatis-plus.generator.strategy.super-service-impl-class=yourpackage.BaseServiceImpl mybatis-plus.generator.strategy.super-mapper-class=yourpackage.BaseMapper mybatis-plus.generator.strategy.super-controller-class=yourpackage.BaseController mybatis-plus.generator.strategy.naming=underline_to_camel mybatis-plus.generator.strategy.column-naming=underline_to_camel mybatis-plus.generator.strategy.entity-boolean-column-remove-prefix=true mybatis-plus.generator.strategy.entity-table-field-annotation-enable=true mybatis-plus.generator.strategy.entity-lombok-model=true mybatis-plus.generator.strategy.entity-serializable=true mybatis-plus.generator.strategy.entity-builder-model=true mybatis-plus.generator.strategy.entity-all-lombok-models=true mybatis-plus.generator.strategy.entity-serializable=false mybatis-plus.generator.strategy.entity-boolean-column-remove-prefix=true mybatis-plus.generator.strategy.entity-table-field-annotation-enable=true mybatis-plus.generator.strategy.entity-lombok-model=true mybatis-plus.generator.strategy.entity-serializable=true mybatis-plus.generator.strategy.entity-builder-model=true mybatis-plus.generator.strategy.entity-all-lombok-models=true mybatis-plus.generator.strategy.entity-serializable=false mybatis-plus.generator.strategy.entity-boolean-column-remove-prefix=true mybatis-plus.generator.strategy.entity-table-field-annotation-enable=true mybatis-plus.generator.strategy.entity-lombok-model=true mybatis-plus.generator.strategy.entity-serializable=true mybatis-plus.generator.strategy.entity-builder-model=true mybatis-plus.generator.strategy.entity-all-lombok-models=true mybatis-plus.generator.strategy.include=table1,table2 mybatis-plus.generator.strategy.exclude=table3,table4 mybatis-plus.generator.template.mapper=/templates/mapper.xml mybatis-plus.generator.template.entity=/templates/entity.java mybatis-plus.generator.template.service=/templates/service.java mybatis-plus.generator.template.service-impl=/templates/serviceImpl.java mybatis-plus.generator.template.controller=/templates/controller.java ``` 在上面的配置文件中,需要注意以下几点: 1. 数据源配置中需要指定 SQLite 数据库的连接信息,包括数据库文件路径和 JDBC 驱动类名。 2. MyBatis Plus 配置中需要指定 Mapper 文件的存放路径、实体类的包名和 ID 自动生成方式等。 3. 代码生成器配置中需要指定代码生成的基础配置,包括作者名、输出目录、是否覆盖已有文件等。 4. 策略配置中需要指定生成代码的规则和模板文件,包括实体类的父类、命名策略、是否使用 Lombok 等。 根据实际需求修改配置文件后,执行以下命令即可生成代码: ``` java -jar mybatis-plus-generator.jar -configFile generator-config.xml ``` 其中 `mybatis-plus-generator.jar` 是 MyBatis Plus 代码生成器的可执行文件,`generator-config.xml` 是配置文件的路径。执行命令后,代码生成器会根据配置文件中的规则和模板文件生成相应的代码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值