mybatis plus 代码生成器使用splite数据库
时间: 2023-08-10 11:30:40 浏览: 53
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` 是配置文件的路径。执行命令后,代码生成器会根据配置文件中的规则和模板文件生成相应的代码。