【问题解决】Mybatis Plus Generator(新代码生成器)+达梦数据库,创建数据库连接失败

前言

使用Mybatis Plus Generator(新代码生成器)+达梦数据库,执行生成方法失败
无法创建数据库连接

问题描述

  1. 创建数据源配置,连接配置参照官网

    jdbc:dm://localhost:5236/DMSERVER?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8

  2. 启动Mybatis Plus Generator(代码生成器)

  3. 报错

错误日志输出

  1. 创建IDatabaseQuery实例出现错误

  2. dm.jdbc.driver.DMException: 网络通信异常

  3. connect: Address is invalid on local machine, or port is not valid on remote machine

Process finished with exit code 1

在这里插入图片描述
在这里插入图片描述

尝试解决

  1. 添加支持IPv4:-Djava.net.preferIPv4Stack=true
  2. 连接配置增加:compatibleMode=oracle

最终解决方法

数据库连接配置去除服务实例名称,只需要服务ip和端口

jdbc:dm://localhost:5236?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8

生成成功

在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 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
发出的红包

打赏作者

芒果-橙

谢谢啦!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值