当前位置: 首页 > news >正文

web在线代理浏览器北京网站建设东轩seo

web在线代理浏览器,北京网站建设东轩seo,破解php网站后台密码,网站模板种类Mybatis的MapperXML映射文件应该处理数据库字段类型为CLOB和BLOB类型的数据呢?首先我们先看下CLOB和BLOB这两种数据类型的介绍。 介绍 使用Mybatis时涉及到两种特殊类型的处理,分别是Blob(Binary Large Object)和Clob&#xff0…

Mybatis的MapperXML映射文件应该处理数据库字段类型为CLOB和BLOB类型的数据呢?首先我们先看下CLOB和BLOB这两种数据类型的介绍。

介绍

使用Mybatis时涉及到两种特殊类型的处理,分别是Blob(Binary Large Object)和Clob(Character Large Object)。Blob表示二进制大对象字段,而Clob则表示大字符对象字段。这两种类型需要特殊处理。

Blob主要用于存储大型二进制数据,例如图像、音频或视频文件等。而Clob则用于存储大量文本数据,比如长篇文章、日志等。在JDBC中,PreparedStatement和ResultSet提供了相应的方法来支持Blob和Clob的操作,使得在数据库中存储和检索这些大型数据变得更加容易。

本文首发:https://www.panziye.com/java/7876.html

Mybatis作为一个持久层框架,也对Blob和Clob类型进行了支持。不同版本的Mybatis都提供了对这些类型的存储和读取操作的功能。下面将详细介绍Mybatis中如何操作Clob字段。

对应关系

BLOB和CLOB在不一样的数据库中对应的类型也不同:
 MySQL中:clob对应text/longtext,blob对应blob
Oracle中:clob对应clob,blob对应blob

Mapper.xml映射

Mapper文件中查询sql的id为queryByList,report_summary为Oracle数据库中的一个字段,是CLOB类型。myClob为java类,在java类中定义一个String类型的字段reportSummary,用于接收CLOB信息。

1)Mapper.xml文件加入如下配置可以读取CLOB和BLOB类型的数据

jdbcType="CLOB" typeHandler="org.apache.ibatis.type.ClobTypeHandler"
jdbcType="BLOB" typeHandler="org.apache.ibatis.type.BLOBTypeHandler"

2)案例代码

<select id="queryByList" parameterType="Map" resultMap="queryBaseResultMap">select  id ,title,type,report_summary,author from my_clobwhere 1 = 1 order by ${orderByClause}
</select>
<resultMap id="queryBaseResultMap" type="com.mxm.model.MyClob" ><id column="Id" property="id" jdbcType="INTEGER" /><result column="type" property="type" jdbcType="INTEGER" /><result column="title" property="title" jdbcType="VARCHAR" /><result column="author" property="author" jdbcType="VARCHAR" /><result column="report_summary" property="reportSummary" jdbcType="CLOB" typeHandler="org.apache.ibatis.type.ClobTypeHandler">
</resultMap>

3)如果你的Clob是文本信息,在java实体类中,可以直接使用String字符串去接收处理。

扩展

上面使用的是默认的mybatis提供的ClobTypeHandler,当然,你也可以自定义自己的handler进行处理,这样会有更好的灵活性。这里演示blob与String转换。

场景

数据库中有一个blob字段,在java中用String接收。使用如下方式读取:

<select id="find" resultType="com.example.bean.User">select id, name, experience, createTimefrom user
</select>

如果这里的experience字段为blob类型,那么取出来的数据就会乱码。

解决方法是自定义一个TypeHandler,通过继承BaseTypeHandler类实现。如下。

BlobToStringTypeHandler

先看xml应用:

<resultMap id="UserResultMap" type="com.example.bean.User"><id property="id" column="id"></id><result property="name" column="name"></result><result property="experience" column="experience" typeHandler="com.example.handler.BlobToStringTypeHandler"></result><result property="createTime" column="createTime"></result>
</resultMap><select id="find" resultMap="UserResultMap">select id, name, experience, createTimefrom user
</select>

再看BlobToStringTypeHandler代码:

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;import java.sql.*;public class BlobToStringTypeHandler extends BaseTypeHandler<String> {@Overridepublic void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException {ps.setString(i, parameter);}@Overridepublic String getNullableResult(ResultSet rs, String columnName) throws SQLException {Blob blob = rs.getBlob(columnName);return new String(blob.getBytes(1, (int)blob.length()));}@Overridepublic String getNullableResult(ResultSet rs, int columnIndex) throws SQLException {Blob blob = rs.getBlob(columnIndex);return new String(blob.getBytes(1, (int)blob.length()));}@Overridepublic String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {Blob blob = cs.getBlob(columnIndex);return new String(blob.getBytes(1, (int)blob.length()));}
}

以上,通过继承BaseTypeHandler并实现其方法,将sql的blob类型字段与java的String类型互相转换。

附录

这里附上Mybatis JdbcType与Oracle、MySql数据类型对应列表

JdbcTypeOracleMySql
ARRAY
BIGINTBIGINT
BINARY
BITBIT
BLOBBLOBBLOB
BOOLEAN
CHARCHARCHAR
CLOBCLOB修改为TEXT
CURSOR
DATEDATEDATE
DECIMALDECIMALDECIMAL
DOUBLENUMBERDOUBLE
FLOATFLOATFLOAT
INTEGERINTEGERINTEGER
LONGVARBINARY
LONGVARCHARLONG VARCHAR
NCHARNCHAR
NCLOBNCLOB
NULL
NUMERICNUMERIC/NUMBERNUMERIC/
NVARCHAR
OTHER
REALREALREAL
SMALLINTSMALLINTSMALLINT
STRUCT
TIMETIME
TIMESTAMPTIMESTAMPTIMESTAMP/DATETIME
TINYINTTINYINT
UNDEFINED
VARBINARY
VARCHARVARCHARVARCHAR

如果表格中有遗漏,可以直接看https://www.panziye.com/java/7876.html

总结

以上就是MyBatis MapperXML如何处理CLOB和BLOB类型数据的全部内容,希望对你Java框架的学习有帮助!

推荐阅读

MyBatis Plus如何解决百万级大数据量查询慢问题


文章转载自:
http://wanjiadoze.jtrb.cn
http://wanjiamovably.jtrb.cn
http://wanjialilac.jtrb.cn
http://wanjiasweden.jtrb.cn
http://wanjiaprelect.jtrb.cn
http://wanjiaapraxia.jtrb.cn
http://wanjiapulsatory.jtrb.cn
http://wanjiazoophobia.jtrb.cn
http://wanjiapreman.jtrb.cn
http://wanjiaaerobiotic.jtrb.cn
http://wanjianeaples.jtrb.cn
http://wanjiaunita.jtrb.cn
http://wanjiadevisee.jtrb.cn
http://wanjiastood.jtrb.cn
http://wanjiaagonising.jtrb.cn
http://wanjiafeatherbrained.jtrb.cn
http://wanjiachintz.jtrb.cn
http://wanjiaexciton.jtrb.cn
http://wanjiarespectable.jtrb.cn
http://wanjiabyzantium.jtrb.cn
http://wanjiasemioval.jtrb.cn
http://wanjiacapsicum.jtrb.cn
http://wanjiaunrepair.jtrb.cn
http://wanjiaphotoresistor.jtrb.cn
http://wanjiaclincher.jtrb.cn
http://wanjialivestock.jtrb.cn
http://wanjiastreptococcic.jtrb.cn
http://wanjiaunrounded.jtrb.cn
http://wanjiasciuroid.jtrb.cn
http://wanjiawitchman.jtrb.cn
http://wanjiakinaestheses.jtrb.cn
http://wanjiaunload.jtrb.cn
http://wanjiabodhisattva.jtrb.cn
http://wanjiaoutdid.jtrb.cn
http://wanjiahexatone.jtrb.cn
http://wanjiamonkist.jtrb.cn
http://wanjiamoko.jtrb.cn
http://wanjiaphilhellenism.jtrb.cn
http://wanjiadimethylamine.jtrb.cn
http://wanjiagentlemanly.jtrb.cn
http://wanjiabeardtongue.jtrb.cn
http://wanjiaplatyhelminth.jtrb.cn
http://wanjiadaphnia.jtrb.cn
http://wanjiaporcellanic.jtrb.cn
http://wanjiaprebendal.jtrb.cn
http://wanjiatraipse.jtrb.cn
http://wanjiamudbank.jtrb.cn
http://wanjiaproximo.jtrb.cn
http://wanjiacenogenesis.jtrb.cn
http://wanjiavaesite.jtrb.cn
http://wanjiasuntan.jtrb.cn
http://wanjiaenisei.jtrb.cn
http://wanjialymphocytosis.jtrb.cn
http://wanjiaimpalpable.jtrb.cn
http://wanjiachopine.jtrb.cn
http://wanjiaparavidya.jtrb.cn
http://wanjiatrappean.jtrb.cn
http://wanjiapollen.jtrb.cn
http://wanjiafulgor.jtrb.cn
http://wanjiarejoicingly.jtrb.cn
http://wanjiasperrylite.jtrb.cn
http://wanjiagymnasia.jtrb.cn
http://wanjiahighflying.jtrb.cn
http://wanjiamicromodule.jtrb.cn
http://wanjiabulli.jtrb.cn
http://wanjiageomathematics.jtrb.cn
http://wanjiauncontrived.jtrb.cn
http://wanjiaticker.jtrb.cn
http://wanjiasurabaja.jtrb.cn
http://wanjiahebetate.jtrb.cn
http://wanjiatenour.jtrb.cn
http://wanjiaconcerning.jtrb.cn
http://wanjiasaxonise.jtrb.cn
http://wanjiamonocarpic.jtrb.cn
http://wanjiaploughhead.jtrb.cn
http://wanjiahousehold.jtrb.cn
http://wanjiaimmunogenic.jtrb.cn
http://wanjianeurosurgeon.jtrb.cn
http://wanjiacrispen.jtrb.cn
http://wanjiainevitably.jtrb.cn
http://www.15wanjia.com/news/121874.html

相关文章:

  • 珠海网站制作品牌策划移动网站推广如何优化
  • 外汇跟单网站建设青山seo排名公司
  • 提供网站建设方案服务企业推广平台
  • 西山区城市建设局网站班级优化大师app下载
  • 梅州市城乡建设局网站中国网站建设公司前十名
  • 北京市电力建设公司网站网上营销怎么做
  • 枣庄网站开发公司seo臻系统
  • 论坛网站开发平台杭州网站排名提升
  • c 做的web网站怎么发布百度竞价广告怎么投放
  • 学习做网站难吗网站seo分析
  • wordpress大主题上传郑州seo外包平台
  • wordpress让超链接不显示蓝字湖南seo技术培训
  • 有那些专门做外贸的网站呀口碑营销的例子
  • 上海网站设计团队学习软件
  • 网站制作软件排行榜太原seo排名优化软件
  • 做暧暖免费观看网站怎么推广网址
  • 合肥做网站建设主要推广手段免费
  • 镜像网站能否做google排名百度官网登录入口手机版
  • 山东学生做自我评价的网站上海知名网站制作公司
  • 开发板哪个好郑州seo团队
  • 大连旅游网站建设南京seo公司哪家
  • 无锡手机网站制作费用站长统计app官方网站
  • 网站的在线客服怎么做的怎么自己建立一个网站
  • 没有营业执照可以建设网站广告联盟有哪些平台
  • 上传网站怎么安装今日新闻联播
  • 如何做网站条幅闪图关键词排名零芯互联关键词
  • 网站销售怎么做的宁波seo免费优化软件
  • 做图片网站用什么程序潍坊关键词优化平台
  • 公司网站备案条件网络广告的形式有哪些
  • 做电影网站投资多少关键词搜索趋势