Mybatis 生成器缺少方法

Mybatis Generator missing methods

我发现在连接mariadb时生成的映射接口中缺少一些方法,生成的mapper是这样的:

public interface Mapper {
    int insert(Record record);

    int insertSelective(Record record);
}

应该是什么:

public interface Mapper {
    int deleteByPrimaryKey(Record id);

    int insert(Record record);

    int insertSelective(Record record);

    City selectByPrimaryKey(Record id);

    int updateByPrimaryKeySelective(Record record);

    int updateByPrimaryKey(Record record);
}

我尝试了几种不同的连接器库,包括 mysql-connector-java 和 mariadb-java-client。而且连接mysql时生成的代码是正确的,这提醒我mybatis generator 1.3.6是否不支持mariadb 5.7.20? 顺便说一句,mysql 的版本是 5.7。 这是我的 config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
  PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

<generatorConfiguration>

  <classPathEntry location="/maven/repo/org/mariadb/jdbc/mariadb-java-client/2.2.1/mariadb-java-client-2.2.1.jar" />

  <context id="mybatisgen" targetRuntime="MyBatis3">

    <commentGenerator>
      <property name="suppressAllComments" value="true" />
      <property name="suppressDate" value="true" />
    </commentGenerator>

    <jdbcConnection driverClass="org.mariadb.jdbc.Driver"
        connectionURL="jdbc:mariadb://127.0.0.1:3306/db?characterEncoding=utf8"
        userId="user"
        password="password">
    </jdbcConnection>

    <javaTypeResolver >
      <property name="forceBigDecimals" value="false" />
    </javaTypeResolver>

    <javaModelGenerator targetPackage="me.model" targetProject="src">
      <property name="enableSubPackages" value="true" />
      <property name="trimStrings" value="true" />
    </javaModelGenerator>

    <sqlMapGenerator targetPackage="me.mapper"  targetProject="src">
      <property name="enableSubPackages" value="true" />
    </sqlMapGenerator>

    <javaClientGenerator type="XMLMAPPER" targetPackage="me.dao"  targetProject="src">
      <property name="enableSubPackages" value="true" />
    </javaClientGenerator>

    <table tableName="test_table" domainObjectName="ATable" 
        enableCountByExample="false" enableUpdateByExample="false"
        enableDeleteByExample="false" enableSelectByExample="false"
        selectByExampleQueryId="false">     
    </table>

  </context>
</generatorConfiguration>

当 MyBatis Generator 无法从 JDBC 驱动程序(它调用 DatabaseMetaData.getPrimaryKeys)获取主键信息时会发生这种情况。

当 JDBC 驱动程序无法 return 时,您可以使用 VirtualPrimaryKey 插件(记录在 http://www.mybatis.org/generator/reference/plugins.html 中)手动指定 table信息。