zoukankan      html  css  js  c++  java
  • mybatis-generator 类型转化插件

    因为mybatis的tinyint默认映射为bit类型,代码不方便操作和转换。因此需要对类型进行转化

    插件地址:(https://github.com/suyin58/mybatis-generator-tddl/blob/master/generator-plugin/src/main/java/com/toolplat/generator/plugins/JavaTypeResolverMybatisDefaultImpl.java)

    插件需要继承JavaTypeResolverDefaultImpl,并重写overrideDefaultType方法。针对需要转化的数据类型进行特殊处理

    public class JavaTypeResolverMybatisDefaultImpl extends JavaTypeResolverDefaultImpl {
    
        @Override
        protected FullyQualifiedJavaType overrideDefaultType(IntrospectedColumn column, FullyQualifiedJavaType defaultType) {
            FullyQualifiedJavaType answer = defaultType;
    
            switch (column.getJdbcType()) {
                case Types.BIT:
                    answer = this.calculateBitReplacement(column, defaultType);
                    break;
                case Types.NUMERIC:
                case Types.DECIMAL:
                    answer = this.calculateBigDecimalReplacement(column, defaultType);
                    break;
                case Types.TINYINT:
                    answer = new FullyQualifiedJavaType(Integer.class.getName());
                    break;
                default:
                    break;
            }
    
            return answer;
        }
    }
    View Code

    配置文件中添加该配置:(https://github.com/suyin58/mybatis-generator-tddl/blob/master/generator-test/src/test/resources/generatorConfigMyBatis3.xml)

     <!--
            默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer
            true,把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal
            -->
            <javaTypeResolver type="com.toolplat.generator.plugins.JavaTypeResolverMybatisDefaultImpl">
                <property name="forceBigDecimals" value="true" />
            </javaTypeResolver>
    View Code
  • 相关阅读:
    异步FIFO总结
    异常检测参考
    Java数据库连接技术
    Eclipse Decompiler不生效解决办法
    mysql常用操作
    时间序列预测——Tensorflow.Keras.LSTM
    AR(I)MA时间序列建模过程——步骤和python代码
    MySQL优化实例
    MySQL性能优化经验
    高性能MySQL笔记 第6章 查询性能优化
  • 原文地址:https://www.cnblogs.com/loveyou/p/13883276.html
Copyright © 2011-2022 走看看