Mybatis plus 处理 blob字段

6 篇文章 0 订阅
2 篇文章 0 订阅

实体定义:

/**
 * 序列sql blob写入byte[]
 */
private byte[] serialSql;

/**
 * 序列sql字符串   读取blob字符串
 */

@TableField(exist = false,typeHandler = org.apache.ibatis.type.BlobTypeHandler.class)
private String serialSqlStr;

mapper注解配置

@Results({
        @Result(id = true,column = "system_serial_number_id",property = "systemSerialNumberId"),
        @Result(column = "serial_sql",property = "serialSqlStr")
})

插入blob数据:

String serialSqlStr = systemSerialNumber.getSerialSqlStr();
if (serialSqlStr != null){
    systemSerialNumber.setSerialSql(serialSqlStr.getBytes(StandardCharsets.UTF_8));
}

查询结果  实体byte[]  不能查出数据

 

谢谢你的来访,希望能对你有所帮助!

  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MyBatis-Plus is a powerful enhancement library for MyBatis, which provides additional features and utilities to simplify database operations in Java applications. It supports various data types, including BLOB (Binary Large Object). To handle BLOB data types with MyBatis-Plus, you can follow these steps: 1. Ensure that you have the required dependencies in your project. MyBatis-Plus is typically used together with MyBatis, so make sure you have both dependencies configured. 2. Define the entity class that represents the table containing the BLOB column. In the entity class, you can use the @TableField annotation to specify the column's data type as BLOB. For example: ```java @TableField(typeHandler = BlobTypeHandler.class) private byte[] blobData; ``` 3. Configure the MyBatis-Plus type handler for BLOB. MyBatis-Plus provides a built-in BLOB type handler called BlobTypeHandler, which can be used to handle BLOB columns. You can specify this type handler for the BLOB column in your MyBatis XML mapper file or using the @TableField annotation as shown above. With these steps, MyBatis-Plus will handle the BLOB column appropriately during database operations. When retrieving the BLOB data, it will be automatically converted to a byte array. When inserting or updating the BLOB data, you can pass a byte array to the corresponding setter method in your entity class. provides some video tutorials related to integrating MyBatis and Redis in a high-concurrency seckill system, but it does not directly address the specific question about handling BLOB data types with MyBatis-Plus. mentions an error related to the "getString" method not implemented for a specific database driver class. This error seems unrelated to the question about MyBatis-Plus and BLOB handling. briefly mentions that if you don't use certain annotations, the data values may turn into memory addresses. However, it does not provide any direct information about MyBatis-Plus and BLOB handling. In summary, to handle BLOB data types with MyBatis-Plus, you need to define the entity class with the appropriate column type and configure the MyBatis-Plus type handler for BLOB.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值