mybatis generator生成映射文件时,含有重复结点

问题描述

之前用mybatis generator的自动生成代码的插件没有出现任何问题,但是前几天做作业时,通过generator插件自动生成代码,结果Springboot项目都启动不起来,结果通过日志一看是mybatis自动生成的映射文件出现了错误,出现了重复的节点:

<resultMap id="BaseResultMap" type="com.boss.redis.entity.User">
  <id column="id" jdbcType="INTEGER" property="id" />
  <result column="name" jdbcType="VARCHAR" property="name" />
  <result column="pwd" jdbcType="VARCHAR" property="pwd" />
  <result column="phone" jdbcType="CHAR" property="phone" />
  <result column="address" jdbcType="VARCHAR" property="address" />
</resultMap>

<resultMap id="BaseResultMap" type="com.boss.redis.entity.User">
  <result column="U_NO" jdbcType="INTEGER" property="uNo" />
  <result column="U_USERNAME" jdbcType="VARCHAR" property="uUsername" />
  <result column="U_PASSWORD" jdbcType="VARCHAR" property="uPassword" />
  <result column="U_NICKNAME" jdbcType="VARCHAR" property="uNickname" />
  <result column="U_ID" jdbcType="VARCHAR" property="uId" />
  <result column="U_TYPE" jdbcType="INTEGER" property="uType" />
  <result column="U_BALANCE" jdbcType="REAL" property="uBalance" />
</resultMap>

莫名其妙,第二个结点的表字段我都没有建立过。

问题解决

通过网上的查询发现很多人和我遇到了相同的问题,其解决方法是在generatorConfig.xml文件的<jdbcConnection>标签加入<property name="nullCatalogMeansCurrent" value="true" />标签。

<!--数据库链接URL,用户名、密码 -->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/test?serverTimezone=UTC" userId="root" password="huang123">
    <property name="nullCatalogMeansCurrent" value="true" />
</jdbcConnection>

 官方解释

MySql does not properly support SQL catalogs and schema. If you run the create schema command in MySql, it actually creates a database - and the JDBC driver reports it back as a catalog. But MySql syntax does not support the standard catalog..table SQL syntax.

For this reason, it is best to not specify either catalog or schema in generator configurations. Just specify table names and specify the database in the JDBC URL.

If you are using version 8.x of Connector/J you may notice that the generator attempts to generate code for tables in the MySql information schemas (sys, information_schema, performance_schema, etc.) This is probably not what you want! To disable this behavior, add the property "nullCatalogMeansCurrent=true" to your JDBC URL.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值