欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

如何解決MybatisGenerator將tinyint映射為Byte和Boolean的問題

小編給大家分享一下如何解決Mybatis Generator將tinyint映射為Byte和Boolean的問題,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

湖濱ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來市場(chǎng)廣闊!成為成都創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18980820575(備注:SSL證書合作)期待與您的合作!

1. 對(duì)于tinyint(4)映射為Byte

1.1 環(huán)境
  • spring boot 2.1.x

  • mybatis

  • tk.mybatis

  • MySQL

1.2 自定義類型解析器

(1) 新建以下類

public class CustomerJavaTypeResolver extends JavaTypeResolverDefaultImpl {

    public CustomerJavaTypeResolver() {
        super();
        //把數(shù)據(jù)庫的 TINYINT 映射成 Integer
        super.typeMap.put(Types.TINYINT, new JavaTypeResolverDefaultImpl.JdbcTypeInformation("TINYINT", new FullyQualifiedJavaType(Integer.class.getName())));
    }
}

(2)在pom.xml中加入

<build>
        <plugins>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.6</version>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.29</version>
                    </dependency>
                    <!--<dependency>
                        <groupId>org.mybatis.generator</groupId>
                        <artifactId>mybatis-generator-core</artifactId>
                        <version>1.3.6</version>
                    </dependency>-->
                    <dependency>
                        <groupId>com.taco.cloud</groupId>
                        <artifactId>-generator-core</artifactId>
                        <version>1.0-SNAPSHOT</version>
                    </dependency>
                    <dependency>
                        <groupId>tk.mybatis</groupId>
                        <artifactId>mapper</artifactId>
                        <version>4.1.5</version>
                    </dependency>
                </dependencies>
                <!--<executions>
                    <execution>
                        <id>Generate MyBatis Artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>-->
                <configuration>
                    <!--允許移動(dòng)生成的文件 -->
                    <verbose>true</verbose>
                    <!-- 是否覆蓋 -->
                    <overwrite>true</overwrite>
                    <!-- 自動(dòng)生成的配置 -->
                    <configurationFile>
                        src/main/resources/mybatis-generator.xml</configurationFile>
                </configuration>
            </plugin>
        </plugins>
    </build>

(3)修改mybatis-generator.xml文件,加入

<javaTypeResolver type="com.taco.springcloud.generator.CustomerJavaTypeResolver">
            <!--
            true:使用BigDecimal對(duì)應(yīng)DECIMAL和 NUMERIC數(shù)據(jù)類型
            false:默認(rèn),
               scale>0;length>18:使用BigDecimal;
               scale=0;length[10,18]:使用Long;
               scale=0;length[5,9]:使用Integer;
               scale=0;length<5:使用Short;
             -->
            <property name="forceBigDecimals" value="false"/>

        </javaTypeResolver>

2. 對(duì)于tinyint(1)映射為Boolean情況

2.1 解決方法
  1. JDBC的URL增加 tinyInt1isBit=false參數(shù),注意參數(shù)名區(qū)分大小寫,否則不生效

    例如:jdbc:mysql://${ucmha.proxy1_2.host}/${db.mysql.db}?tinyInt1isBit=false

  2. 用tinyint(2)代替

以上是“如何解決Mybatis Generator將tinyint映射為Byte和Boolean的問題”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

文章名稱:如何解決MybatisGenerator將tinyint映射為Byte和Boolean的問題
標(biāo)題路徑:http://chinadenli.net/article0/jiigio.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、微信公眾號(hào)網(wǎng)站導(dǎo)航、虛擬主機(jī)自適應(yīng)網(wǎng)站、網(wǎng)站營(yíng)銷

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化