MyBatis--BlobTypeHandler读取Blob类型字段

I2C总线原理及总线信号的实现 I2C总线是一种多主机总线,连接IIC总线上的器件分为主机和从机,主机有权发起和结束一次通信,而从机只能被主机呼叫;当总线上有多个主机同时启用总线时,I2C也具备冲突检测和仲裁的功能来防止错误产生;每个连接到IIC总线上的器件都有一个唯一的地址(7bit),且每个器件都可以作为主机也可以作为从机(同一时刻只能有一个主机),总线上的器件增加和删除不影响其他器件正常工作;I2C总线在通信时总线上发送数据的器件为发送器,接收数据的器件为接收器;主要用于近距离(抗干扰能力稍弱),低速的芯片之间的通信(传输视频,带宽 阅读详情
BlobTypeHandler读取Blob类型字段

MyBatis 对数据库的 Blob 字段也进行了支持,它提供了一个 BlobTypeHandler,为了应付更多的场景,它还提供了 ByteArrayTypeHandler,只是它不太常用,这里为读者展示 BlobTypeHandler 的使用方法。首先建一个表。

create table file(
    id int(12) not null auto_increment,
    content blob not null,
    primary key(id)
);

创建一个 POJO,用于处理这个表,如下所示。:

public class TestFile{
    long id;
    byte[] content;
    /** setter and getter **/
}

这里需要把 content 属性和数据库的 Blob 字段转换,这个时候可以使用系统注册的 typeHandler——BlobTypeHandler 来转换,如下所示。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ssm.chapter5.mapper.FileMapper">
    <resultMap type="com.ssm.chapter5.pojo.TestFile" id="file">
        <id column="id" property="id"/>
        <id column="content" property="content" typeHandler="org.apache.ibatis.type.BlobTypeHandler"/>
    </resultMap>

    <select id="getFile" parameterType="long" resultMap="file"> 
        select id, content from t_file where id = #{id}
    </select>

    <insert id="insertFile" parameterType="com.ssm.chapter5.pojo.TestFile">
        insert into t_file(content) values(#{content})
    </insert>
</mapper>

实际上,不加入加粗代码的 typeHandler 属性,MyBatis 也能检测得到,并使用合适的 typeHandler 进行转换。

在现实中,一次性地将大量数据加载到 JVM 中,会给服务器带来很大压力,所以在更多的时候,应该考虑使用文件流的形式。这个时候只要把 POJO 的属性 content 修改为 InputStream 即可。

如果没有 typeHandler 声明,那么系统就会探测并使用 BlobInputStream TypeHandler 为你转换结果,这个时候需要把加粗代码的 typeHandler 修改为 org.apache.ibatis.type.BlobInputStreamTypeHandler。

因为性能不佳,文件的操作在大型互联网的网站上并不常用。更多的时候,大型互联网的网站会采用文件服务器的形式,通过更为高速的文件系统操作。这是搭建高效服务器需要注意的地方。

【WRFDA实操第一期】服务器中安装 WRFPLUS 和 WRFDA 【WRFDA实操第一期】安装 WRFPLUS 和 WRFDA 阅读详情

相关推荐

华为IC岗笔试刷题含答案(2)

又做了几套题,记录了部分及答案,如有错误,欢迎评论指正。

Ingrid的博客 1万+

MyBatis BlobTypeHandler读取Blob字段

MyBatis 对数据库的 Blob 字段也进行了支持,它提供了一个 BlobTypeHandler,为了应付更多的场景,它还提供了 ByteArrayTypeHandler,只是它不太常用,这里为读者展示 BlobTypeHandler 的使用方法。在现实中,一次性地将大量数据加载到 JVM 中,会给服务器带来很大压力,所以在更多的时候,应该考虑使用文件流的形式。更多的时候,大型互联网的网站会采用文件服务器的形式,通过更为高速的文件系统操作。加粗的代码,使用了 Blob 字段,用于存入文件。

unber的博客 803

手把手教学:用国产GLM-4.6替代Claude4.0,实现AI自动化编程全流程

本文提供了一份详细的教程,指导开发者使用国产GLM-4.6模型替代Claude 4.0,实现AI自动化编程。内容涵盖从获取API密钥、搭建本地环境、改造Claude Code工具到实战开发与VSCode集成的全流程,旨在帮助用户低成本、高效率地体验AI自主编程。

weixin_29070861的博客 553

解决问题记录:mybatis的TypeHandler处理blob字段的写入和读取

场景: 开发中遇到这样一种情况,页面传来一个字符串,数据长度非常大,远远大出了varchar2类型的默认长度4000,这里就用到了oracle的blob字段;(其实这里使用clob字段更好,因为clob是大字符字段而blob是大的字节字段两者都用来存储大的数据,但是使用场景不同) 问题: 我们知道页面传递的字符串类型String,但是blob类型只能接受的byte[]类型,那么mybatis如何实现这两者的转换呢? 1 解决思路 最容易想到在接收之后将字符串转成字节数组 如: string.getBy.

kay'blog 2257

安全虚拟化SEV简单介绍

安全虚拟化SEV简单介绍什么是SEV什么是SVMSME介绍SEV介绍总结 什么是SEV SEV是由AMD提出的安全虚拟化Secure Encrypted Virtualization技术的英文首字母的缩写。简单来说就是主内存控制器具备了加密功能可以对虚拟机内存数据进行保护。在真正介绍SEV之前,我们首先要弄清楚两个关键的基本概念:SVM、SME。下面先简单了解一下SVM和SME。 什么是SVM S...

artine的专栏 6389

全国青少年信息素养大赛图形化(Scratch)编程考点总结

全国青少年信息素养大赛图形化(Scratch)编程考点总结

伶俐角少儿编程 382

mysql blob typehandler

MySQL Blob TypeHandler简介及使用示例 在MySQL数据库中,Blob类型是一种用来存储二进制数据的字段类型。Blob类型可以存储大量的二进制数据,比如图片、声音、视频等。为了更好地处理Blob类型的数据,我们可以使用TypeHandler来实现对Blob类型的处理。 MySQL Blob TypeHa...

weixin_35094917的博客 178

libVLC 视频抓图

libVLC 中通过libvlc_video_take_snapshot核心接口来截图。以下是VLC播放器中使用的截图界面,我们仿照这个做一个界面。首先,你需要初始化 libVLC 实例和媒体播放器对象。1. 初始化 libVLC 和媒体播放器。菜单添加action,并响应槽函数。生成目录下snap.png。

希望能帮助大家,希望大家多多支持,你们的支持是我前进的动力。 1940

关于blob类型的字段使用mybatis进行对mysql数据库的读取,修改properties文件后缀名为yml的问题,报不能bound statement的错的解决

org.apache.ibatis.type.BlobTypeHandler是MyBatis框架中的一个类型处理器(TypeHandler),用于处理数据库中的BLOB(binary large object)数据类型。在数据库中,BLOB类型通常用于存储较大的二进制数据,如图像、音频、视频等。BlobTypeHandler的作用就是在Java对象和数据库之间进行转换,确保BLOB类型数据在数据库和Java代码之间的正确处理。

weixin_54401017的博客 1065

低功耗设计:如何计算power switch的数量?

power switch加多了漏电高,加少了ir drop会有问题,具体加多少合适要如何计算呢?这里可以给一个参考方式。 第一步,先选switch cell的类型 通常选用HVT类型的switch cell,优点是漏电更低,缺点也很明显,电阻大,压降也大,switch cell的大小选择,可以选择(开启电阻x面积)最小的switch cell,即单位面积提供最小并联电阻的cell类型。 第二步,计算数量 选好类型,确定了开启电阻,可以按照如下公式计算数量: Ron/Xnum • W/V = V•P

m0_61544122的博客 3577

(10)三相三绕组变压器的建模仿真

建立了三相三绕组变压器组的Simulink仿真模型,通过实例进行了仿真计算。

weixin_45670943的博客 1143

Mybatis自定义TypeHandler向数据库中插入Blob数据

Mybatis自定义TypeHandler向数据库中插入Blob数据

scorpio的博客 3947

Android oom_adj 更新原理(一)

通过之前的两篇博文《lmkd 机制详解》和《lmkd中adj score的算法剖析》中,根据计算出来的 min_score_adj 选择大于该值的 oom_adj 的进程进行 kill 处理。oom_adj 随着应用状态的不同其值也是伴随着变化的。本文将通过源码剖析 oom_adj 更新的原理。

私房菜 2655

mybaties连接sqlite,并读取blob类型数据时,报 java.sql.SQLException: not implemented by SQLite JDBC driver错误

mybaties连接sqlite,并读取blob类型数据时,报 java.sql.SQLException: not implemented by SQLite JDBC driver错误 由于某些原因,不能共开公司代码,这里是自用代码片段 场景: 具体需求,要求像springboot连接mysql或者pgsql数据库一样,在application配置文件中配置sqlite数据库信息,并实现对blob类型数据(我们的库中有该类型的数据)的读写,按照平常一样写好controller、service、dao、m

梦殇王子的博客 2932

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

mybatis查询mysql blob字段_mybatis处理blob类型字段

参考:https://blog.youkuaiyun.com/kelei2015/article/details/84964866mysql数据库中blob类型字段 在实体类中表示:private String content; //正文内容处理方法:import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFacto...

weixin_36486455的博客 1901

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

MyBatis处理CLOB/BLOB类型数据,解决读取问题

Mapper.xml文件加入如下配置可以读取CLOB和BLOB类型的数据 jdbcType="CLOB" typeHandler="org.apache.ibatis.type.ClobTypeHandler" jdbcType="BLOB" typeHandler="org.apache.ibatis.type.BLOBTypeHandler"

luckySnow的博客 1万+

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Mybatis解决数据库Blob类型存储与读取问题

1.Blob介绍 首先,先简单介绍下数据库Blob字段,Blob(Binary Large Object)是指二进制大对象字段,顺带介绍下Clob类型,Clob(Character Large Object)是指大字符对象。其中Blob是为存储大的二进制数据而设计的,而Clob是为存储大的文本数据而设计的。JDBC的PreparedStatement和ResultSet都提供了相应的方法来支持Blob和Clob操作,Mybatis各版本也支持对Blob或者Clob的存储以及读取操作,本文详细介绍Mybat

qq_34412985的博客 8417

MyBatis XML映射处理CLOB和BLOB类型

使用Mybatis时涉及到两种特殊类型的处理,分别是Blob(Binary Large Object)和Clob(Character Large Object)。Blob表示二进制大对象字段,而Clob则表示大字符对象字段。这两种类型需要特殊处理。Blob主要用于存储大型二进制数据,例如图像、音频或视频文件等。而Clob则用于存储大量文本数据,比如长篇文章、日志等。

Java潘老师 2795

Mybatis对MySQL中BLOB字段的读取

创建一个自定义TypeHandle public class BlobTypeHandler extends org.apache.ibatis.type.BlobTypeHandler { } 在mapper.xml里面定义resultmap的result column <resultMap id="faceInfoMap" type="com....pojo.FaceInformation"> <result property="id" column="id">&.

weixin_43871142的博客 1134

MyBatis BLOB字段

项目开发时,有时候需要把一些小的图片直接放到数据库里,比如用户的头像。这时候就要用到blob字段。今天小博老师就以MySQL为例,为大家讲解下如何使用Mybatis操作MySQL的blob类型字段 MySQL的有四种blob类型: 类型大小(单位:字节) TinyBlob最大255 Blob最大65K MediumBlob最大16M LongBlob最大4G MySQL中的这四种bl...

CatEatApple的专栏 3665

MyBatis-Plus+自定义Hanlder解决ORACLE中Blob类型查询及插入问题

MyBatis-Plus+自定义Hanlder解决ORACLE中Blob类型查询及插入问题

qq_23052017的博客 703

blob字段怎么查看是乱码_Mybatis 数据库Blob字段乱码问题

mapper.xml中设置Blob字段ConvertBlobTypeHandler.javapackagecom.surfilter.utils;importjava.io.ByteArrayInputStream;importjava.io.UnsupportedEncodingException;importjava.sql.Blob;importjava.sql.CallableS...

weixin_39681486的博客 207

mybatis对blob属性数据的处理

实体类对应的类型为byte[] (clob为char[]) 2.resultMap中的对应的字段映射添加 typeHandler <result jdbcType="BLOB" typeHandler="org.apache.ibatis.type.BlobTypeHandler"/> (clob类似) ...

那些年的代码 776

Mybatis解析blob字段的时候报错:No typehandler found for property XXX

&lt;result column="content" property="content" javaType="java.sql.Blob" jdbcType="BLOB" typeHandler="org.apache.ibatis.type.BlobTypeHandler"/&gt; 加上typeHandler就可以了

哎呦叔叔的博客 8286

MyBatisPlus写入和读取mysql blob数据

mybatis plus处理blob数据

Lufwill的博客 2509

Mybatis-Plus实现存储以及读取Java对象

数据库的准备 - MySQL 准备一个字段存储Java对象序列化后的字段 因为不能直接用字符串,所以用成了字节数组(Java) 所以各位可以根据自己的需要选择,以下的几个类型,作为参考 TinyBlob:最大 255 Blob:最大 65KB MediumBlob:最大 16MB LongBlob:最大 4GB 我自己的是Blob Java代码的准备 需要的知识存储,IO以及Mybatis Plus的基础操作 这里用的是SpringBoot + MybatisPlus组合 当然使用Spring + Spr

qq_41491194的博客 2414
上一篇: MyBatis--自定义TypeHandler处理枚举
下一篇: MyBatis--与Spring的整合步骤
吴声子夜歌
博客等级 码龄9年 2687粉丝 2268原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值