MyBatis Generator 1.3.7使用错误的数据类型为Oracle数据库12c生成实体

时间:2018-08-16 11:21:11

标签: oracle mybatis mybatis-generator

我正在使用MyBatis Generator 1.3.7,Oracle数据库12c(由Docker https://hub.docker.com/r/sath89/oracle-12c/运行),JDK 10.0.2。

这是文件generatorConfig.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="/Users/foo/Documents/mybatis/ojdbc7-12.1.0.1.jar"/>
    <context id="context1">
        <plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>
        <plugin type="org.mybatis.generator.plugins.RowBoundsPlugin"/>
        <plugin type="org.mybatis.generator.plugins.CaseInsensitiveLikePlugin"/>
        <plugin type="org.mybatis.generator.plugins.RenameExampleClassPlugin">
            <property name="searchString" value="Example$"/>
            <property name="replaceString" value="Criteria"/>
        </plugin>
        <commentGenerator>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>
        <jdbcConnection connectionURL="jdbc:oracle:thin:dbuser/password@localhost:1521:xe" driverClass="oracle.jdbc.driver.OracleDriver">
        <javaModelGenerator targetPackage="com.example.model" targetProject="src/main/java"/>
        <sqlMapGenerator targetPackage="com.example.repository" targetProject="src/main/resources"/>
        <javaClientGenerator targetPackage="com.example.repository" targetProject="src/main/java" type="XMLMAPPER"/>
        <table tableName="CCY"/>
    </context>
</generatorConfiguration>

我的数据库架构

  CREATE TABLE "CCY" 
   (    "CURRENCY_ID" NUMBER(11,0), 
    "CURRENCY_NAME" NVARCHAR2(128), 
    "EXCHANGE_RATE" NUMBER(18,4), 
    "EXCHANGE_RATE_OPERATOR" NUMBER(1,0), 
    "IS_ACTIVE" NUMBER(1,0), 
    "CA_ACCOUNT" NVARCHAR2(32), 
    "BA_ACCOUNT" NVARCHAR2(32), 
    "PREFIX" NVARCHAR2(20), 
    "CCY_NAME" NVARCHAR2(128), 
    "DECIMAL_SEPERATE" NVARCHAR2(32), 
    "AFTER_DECIMAL" NVARCHAR2(20), 
    "SUBFIX" NVARCHAR2(20), 
    "CONVERT_RATE" NUMBER(18,4), 
    "PREFIX_ENG" NVARCHAR2(32), 
    "CCY_NAME_ENG" NVARCHAR2(32), 
    "DECIMAL_SEPERATE_ENG" NVARCHAR2(32), 
    "AFTER_DECIMAL_ENG" NVARCHAR2(32), 
    "SUBFIX_ENG" NVARCHAR2(32), 
    "CONVERT_RATE_ENG" NUMBER(18,4), 
    "PREFIX_DEFAULT" NVARCHAR2(20), 
    "CCY_NAME_DEFAULT" NVARCHAR2(20), 
    "DECIMAL_SEPERATE_DEFAULT" NVARCHAR2(32), 
    "AFTER_DECIMAL_DEFAULT" NVARCHAR2(32), 
    "SUBFIX_DEFAULT" NVARCHAR2(20), 
    "CONVERT_RATE_DEFAULT" NUMBER(18,4), 
    "PREFIX_DEFAULT_ENG" NVARCHAR2(32), 
    "CCY_NAME_DEFAULT_ENG" NVARCHAR2(32), 
    "DECIMAL_SEPERATE_DEFAULT_ENG" NVARCHAR2(32), 
    "AFTER_DECIMAL_DEFAULT_ENG" NVARCHAR2(32), 
    "SUBFIX_DEFAULT_ENG" NVARCHAR2(32), 
    "CONVERT_RATE_DEFAULT_ENG" NUMBER(18,4), 
    "EXAMPLE_AMOUNT" NUMBER(18,4), 
    "SORT_ORDER" NUMBER(*,0), 
    "VALUE_OF_MONEY" VARCHAR2(2048 BYTE), 
    "CREATED_DATE" TIMESTAMP (6) WITH TIME ZONE, 
    "CREATED_BY" NVARCHAR2(64), 
    "MODIFIED_DATE" TIMESTAMP (6) WITH TIME ZONE, 
    "MODIFIED_BY" NVARCHAR2(64)
   ) SEGMENT CREATION IMMEDIATE 
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 
 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS" ;

   COMMENT ON COLUMN "CCY"."CURRENCY_ID" IS 'Currency identity number';
REM INSERTING into CCY
SET DEFINE OFF;
Insert into CCY (CURRENCY_ID,CURRENCY_NAME,EXCHANGE_RATE,EXCHANGE_RATE_OPERATOR,IS_ACTIVE,CA_ACCOUNT,BA_ACCOUNT,PREFIX,CCY_NAME,DECIMAL_SEPERATE,AFTER_DECIMAL,SUBFIX,CONVERT_RATE,PREFIX_ENG,CCY_NAME_ENG,DECIMAL_SEPERATE_ENG,AFTER_DECIMAL_ENG,SUBFIX_ENG,CONVERT_RATE_ENG,PREFIX_DEFAULT,CCY_NAME_DEFAULT,DECIMAL_SEPERATE_DEFAULT,AFTER_DECIMAL_DEFAULT,SUBFIX_DEFAULT,CONVERT_RATE_DEFAULT,PREFIX_DEFAULT_ENG,CCY_NAME_DEFAULT_ENG,DECIMAL_SEPERATE_DEFAULT_ENG,AFTER_DECIMAL_DEFAULT_ENG,SUBFIX_DEFAULT_ENG,CONVERT_RATE_DEFAULT_ENG,EXAMPLE_AMOUNT,SORT_ORDER,VALUE_OF_MONEY,CREATED_DATE,CREATED_BY,MODIFIED_DATE,MODIFIED_BY) values ('91','LYD','16082,71','0','0','1112','1122',null,'Libyan Dinar',null,null,null,'0',null,null,null,null,null,'0',null,null,null,null,null,'0',null,null,null,null,null,'0','0','130',null,to_timestamp_tz('14-02-2018 18:00:41,370000000 ASIA/HO_CHI_MINH','DD-MM-RRRR HH24:MI:SSXFF TZR'),'ADMIN',to_timestamp_tz('14-02-2018 18:00:41,370000000 ASIA/HO_CHI_MINH','DD-MM-RRRR HH24:MI:SSXFF TZR'),'ADMIN');
Insert into CCY (CURRENCY_ID,CURRENCY_NAME,EXCHANGE_RATE,EXCHANGE_RATE_OPERATOR,IS_ACTIVE,CA_ACCOUNT,BA_ACCOUNT,PREFIX,CCY_NAME,DECIMAL_SEPERATE,AFTER_DECIMAL,SUBFIX,CONVERT_RATE,PREFIX_ENG,CCY_NAME_ENG,DECIMAL_SEPERATE_ENG,AFTER_DECIMAL_ENG,SUBFIX_ENG,CONVERT_RATE_ENG,PREFIX_DEFAULT,CCY_NAME_DEFAULT,DECIMAL_SEPERATE_DEFAULT,AFTER_DECIMAL_DEFAULT,SUBFIX_DEFAULT,CONVERT_RATE_DEFAULT,PREFIX_DEFAULT_ENG,CCY_NAME_DEFAULT_ENG,DECIMAL_SEPERATE_DEFAULT_ENG,AFTER_DECIMAL_DEFAULT_ENG,SUBFIX_DEFAULT_ENG,CONVERT_RATE_DEFAULT_ENG,EXAMPLE_AMOUNT,SORT_ORDER,VALUE_OF_MONEY,CREATED_DATE,CREATED_BY,MODIFIED_DATE,MODIFIED_BY) values ('92','MAD','2254,55','0','0','1112','1122',null,'Moroccan Dirham',null,null,null,'0',null,null,null,null,null,'0',null,null,null,null,null,'0',null,null,null,null,null,'0','0','134',null,to_timestamp_tz('14-02-2018 18:00:41,370000000 ASIA/HO_CHI_MINH','DD-MM-RRRR HH24:MI:SSXFF TZR'),'ADMIN',to_timestamp_tz('14-02-2018 18:00:41,370000000 ASIA/HO_CHI_MINH','DD-MM-RRRR HH24:MI:SSXFF TZR'),'ADMIN');

我运行命令

java -jar /Users/foo/Documents/mybatis/mybatis-generator-core-1.3.7.jar -configfile generatorConfig.xml -overwrite

结果是

package com.example.model;

import java.io.Serializable;
import java.math.BigDecimal;

public class Ccy implements Serializable {
    private Long currencyId;
    private Object currencyName;
    private BigDecimal exchangeRate;
    private Short exchangeRateOperator;
    private Short isActive;
    private Object caAccount;
    private Object baAccount;
    private Object prefix;
    private Object ccyName;
    private Object decimalSeperate;
    private Object afterDecimal;
    private Object subfix;
    private BigDecimal convertRate;
    private Object prefixEng;
    private Object ccyNameEng;
    private Object decimalSeperateEng;
    private Object afterDecimalEng;
    private Object subfixEng;
    private BigDecimal convertRateEng;
    private Object prefixDefault;
    private Object ccyNameDefault;
    private Object decimalSeperateDefault;
    private Object afterDecimalDefault;
    private Object subfixDefault;
    private BigDecimal convertRateDefault;
    private Object prefixDefaultEng;
    private Object ccyNameDefaultEng;
    private Object decimalSeperateDefaultEng;
    private Object afterDecimalDefaultEng;
    private Object subfixDefaultEng;
    private BigDecimal convertRateDefaultEng;
    private BigDecimal exampleAmount;
    private BigDecimal sortOrder;
    private String valueOfMoney;
    private Object createdDate;
    private Object createdBy;
    private Object modifiedDate;
    private Object modifiedBy;

    private static final long serialVersionUID = 1L;

    public Long getCurrencyId() {
        return currencyId;
    }

    public void setCurrencyId(Long currencyId) {
        this.currencyId = currencyId;
    }

    //... more getter, setter...

我期望

private Object currencyName;

成为

private String currencyName;

因为此字段的数据类型为NVARCHAR2(128),并且其他字段相同。如何解决?

1 个答案:

答案 0 :(得分:1)

Mybatis生成器不知道类型<Carousel renderCenterLeftControls={({ previousSlide }) => ( <button onClick={previousSlide}> <i className="fa fa-arrow-left" /> </button> )} renderCenterRightControls={({ nextSlide }) => ( <button onClick={nextSlide}> <i className="fa fa-arrow-right"/> </button> )} > {cards} </Carousel> ,仅知道knows NVARCHAR2类型。

您可以创建自己的JavaTypeResolver,该扩展名可以扩展默认的NVARCHAR并向JavaTypeResolverDefaultImpl添加其他类型。