最近同事使用mybatis-plus处理blob类型数据保存进mysql数据库时报错了,提示如下:
复制代码
1java.lang.IllegalStateException: Type handler was null on parameter mapping for property 'embedding'. It was either not specified and/or could not be found for the javaType (java.sql.Blob) : jdbcType (null) combination.
我之前解决过这个问题,翻了一下git提交记录找到了,最佳实例如下:
一、新增处理blob类型的handler
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34@MappedJdbcTypes(JdbcType.BLOB) @MappedTypes(Blob.class) public class CustomBlobTypeHandler extends BaseTypeHandler<Blob> { @Override public void setNonNullParameter(PreparedStatement ps, int i, Blob parameter, JdbcType jdbcType) throws SQLException { InputStream is = parameter.getBinaryStream(); try { ps.setBinaryStream(i, is, is.available()); } catch (IOException e) { throw new SQLException(e); } } @Override public Blob getNullableResult(ResultSet rs, String columnName) throws SQLException { return rs.getBlob(columnName); } @Override public Blob getNullableResult(ResultSet rs, int columnIndex) throws SQLException { return rs.getBlob(columnIndex); } @Override public Blob getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { return cs.getBlob(columnIndex); } }
二、配置handler
复制代码
1
2
3
4
5
6mybatis-plus: global-config: db-config: id-type: assign_id # 对新增的handler进行配置 type-handlers-package: *.mybatis.handlers
再加一个测试用例测试,问题解决。
最后
以上就是彩色龙猫最近收集整理的关于mybatis-plus存储数据类型不匹配问题解决的全部内容,更多相关mybatis-plus存储数据类型不匹配问题解决内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复