问题: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);