mybatis-plus-generator修改实体类类型映射

mybatis-plus-generator修改实体类类型映射

blob映射为String

问题:mysql数据库的blob会映射成blob,在用mybatis-plus的通用service插入的时候报错
————————————————————————————————————
"org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class java.sql.Blob]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of java.sql.Blob (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information\n at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 1, column: 53] (through reference chain: java.util.ArrayList[0]->com.qf.PositionSystem.entity.Eph[“databuf”])\r\n\tat
————————————————————————————————————
想把blob类型映射成String,方法如下:

新建类MySqlTypeConverter2

package com.qf.CodeGenerator;

import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.rules.IColumnType;

public class MySqlTypeConverter2 extends MySqlTypeConvert {
    @Override
    public IColumnType processTypeConvert(GlobalConfig config, String fieldType) {
        IColumnType ct = super.processTypeConvert(config, fieldType);
        if (ct.getType().contains("Blob")){
            return new IColumnType() {
                @Override
                public String getType() {
                    return "String"; //你想修改的类型
                }

                @Override
                public String getPkg() {
                    return (String)null; //类型所在包
                }
            };
        }
        return ct;
    }
}

在生成类的配置中加如下代码

DataSourceConfig dsc = new DataSourceConfig();
dsc.setTypeConvert(new MySqlTypeConverter2());

修改日期

直接调用gc.setDateType(DateType.ONLY_DATE);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值