欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

mybatis plus自動生成代碼tinyint(1)自動轉(zhuǎn)換為Boolean的問題及解決

 更新時間:2023年08月29日 09:18:39   作者:hank009  
這篇文章主要介紹了mybatis plus自動生成代碼tinyint(1)自動轉(zhuǎn)換為Boolean的問題及解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教

mybatis plus自動生成代碼tinyint(1)自動轉(zhuǎn)換為Boolean

說明下為什么會自動轉(zhuǎn)換為Boolean,是因為mybtisplus提供的默認(rèn)的mysql類型轉(zhuǎn)換器MySqlTypeConvert上特別寫了這一段:

對癥下藥的解決辦法是重寫一個

在注入到配置里:

/**
 * 自定義類型轉(zhuǎn)換
 */
class MySqlTypeConvertCustom extends MySqlTypeConvert implements ITypeConvert{
    @Override
    public IColumnType processTypeConvert(GlobalConfig globalConfig, String fieldType) {
        String t = fieldType.toLowerCase();
        if (t.contains("tinyint(1)")) {
            return DbColumnType.INTEGER;
        }
        return super.processTypeConvert(globalConfig, fieldType);
    }
}

代碼生成器完整代碼

package com.wjj.application;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.po.TableFill;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.config.rules.IColumnType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import java.util.Arrays;
/**
 * @author hank
 */
public class TestGen {
    public static void main(String[] args) {
        AutoGenerator mpg = new AutoGenerator();
        GlobalConfig gc = new GlobalConfig();
        gc.setOutputDir("D://");
        gc.setFileOverride(true);
        //不需要ActiveRecord特性的請改為false
        gc.setActiveRecord(true);
        // XML 二級緩存;
        gc.setEnableCache(false);
        // XML ResultMap
        gc.setBaseResultMap(true);
        // XML columnList
        gc.setBaseColumnList(true);
        gc.setAuthor("mybatisPlus");
        gc.setDateType(DateType.ONLY_DATE);
        gc.setMapperName("%sMapper");
        gc.setXmlName("%sMapper");
        gc.setServiceName("%sService");
        gc.setServiceImplName("%sServiceImpl");
        gc.setControllerName("%sController");
        mpg.setGlobalConfig(gc);
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setDbType(DbType.MYSQL);
        dsc.setDriverName("com.mysql.jdbc.Driver");
        dsc.setUrl("jdbc:mysql://xxxx/xxxxxx?tinyInt1isBit=false&useUnicode=true&characterEncoding=UTF-8&generateSimpleParameterMetadata=true");
        dsc.setUsername("xxxx");
        dsc.setPassword("xxxx");
        dsc.setTypeConvert(new MySqlTypeConvertCustom());
        mpg.setDataSource(dsc);
        StrategyConfig strategy = new StrategyConfig();
        strategy.setTablePrefix("saas_");
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setInclude("saas_medical_history", "saas_medical_history_describe", "saas_medical_history_attachment",
                "saas_medical_history_diagnose", "saas_medical_history_prescription", "saas_medical_history_prescription_subjoin",
                "saas_medical_history_prescription_chinese_list", "saas_medical_history_prescription_generic_list", "saas_medical_history_feature");
        // 指定邏輯刪除字段
        strategy.setLogicDeleteFieldName("is_deleted");
        mpg.setStrategy(strategy);
        PackageConfig pc = new PackageConfig();
        pc.setParent("com.wjj.application");
        String packageModule = ".medicalhistory";
        pc.setController("controller"+packageModule);
        pc.setService("service"+packageModule);
        pc.setServiceImpl("service" + packageModule + ".impl");
        pc.setMapper("mapper" + packageModule);
        pc.setEntity("entity" + packageModule);
        mpg.setPackageInfo(pc);
        mpg.execute();
    }
}
/**
 * 自定義類型轉(zhuǎn)換
 */
class MySqlTypeConvertCustom extends MySqlTypeConvert implements ITypeConvert{
    @Override
    public IColumnType processTypeConvert(GlobalConfig globalConfig, String fieldType) {
        String t = fieldType.toLowerCase();
        if (t.contains("tinyint(1)")) {
            return DbColumnType.INTEGER;
        }
        return super.processTypeConvert(globalConfig, fieldType);
    }
}

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • java并發(fā)編程實例分析

    java并發(fā)編程實例分析

    在本文里我們給大家分享了關(guān)于java并發(fā)編程實例分析以及相關(guān)知識點,需要的朋友們學(xué)習(xí)下。
    2019-03-03
  • Java動態(tài)代理語法Proxy類原理詳解

    Java動態(tài)代理語法Proxy類原理詳解

    這篇文章主要介紹了Java動態(tài)代理語法Proxy類原理詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-04-04
  • SpringBoot實現(xiàn)掃碼登錄的項目實踐

    SpringBoot實現(xiàn)掃碼登錄的項目實踐

    本文主要介紹了SpringBoot實現(xiàn)掃碼登錄的項目實踐,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07
  • SpringMVC如何把后臺文件打印到前臺

    SpringMVC如何把后臺文件打印到前臺

    這篇文章主要介紹了SpringMVC如何把后臺文件打印到前臺,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-09-09
  • Java8中CompletableFuture使用場景與實現(xiàn)原理

    Java8中CompletableFuture使用場景與實現(xiàn)原理

    CompletableFuture是java8引入的新類,該類實現(xiàn)了Future接口和 CompletionStage接口,封裝了future、forkjoin相關(guān)類來執(zhí)行異步,這篇文章主要給大家介紹了關(guān)于Java8中CompletableFuture使用場景與實現(xiàn)原理的相關(guān)資料,需要的朋友可以參考下
    2022-02-02
  • Java設(shè)計模式之享元模式

    Java設(shè)計模式之享元模式

    這篇文章主要為大家詳細(xì)介紹了Java設(shè)計模式之享元模式的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-08-08
  • Java ArrayList擴(kuò)容問題實例詳解

    Java ArrayList擴(kuò)容問題實例詳解

    這篇文章主要介紹了Java ArrayList擴(kuò)容問題實例詳解,分享了相關(guān)代碼示例,小編覺得還是挺不錯的,具有一定借鑒價值,需要的朋友可以參考下
    2018-02-02
  • Mybatis源碼解析之事務(wù)管理

    Mybatis源碼解析之事務(wù)管理

    大家好,本篇文章主要講的是Mybatis源碼解析之事務(wù)管理,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽
    2021-12-12
  • SpringBoot2.0 中 HikariCP 數(shù)據(jù)庫連接池原理解析

    SpringBoot2.0 中 HikariCP 數(shù)據(jù)庫連接池原理解析

    這篇文章主要介紹了SpringBoot2.0 中 HikariCP 數(shù)據(jù)庫連接池原理解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • 如何使用IntelliJ IDEA的HTTP Client進(jìn)行接口驗證

    如何使用IntelliJ IDEA的HTTP Client進(jìn)行接口驗證

    這篇文章主要介紹了如何使用IntelliJ IDEA的HTTP Client進(jìn)行接口驗證,本文給大家分享最新完美解決方案,感興趣的朋友跟隨小編一起看看吧
    2024-06-06

最新評論