Preface
There are two types that need special processing when using Mybatis. Blob (Binary Large Object) refers to binary large object fields, and Clob (Character Large Object) refers to large character objects. Among them, Blobs are designed to store large binary data, while Clobs are designed to store large text data.
JDBC's PreparedStatement and ResultSet both provide corresponding methods to support Blob and Clob operations. Each version of Mybatis also supports storage and reading operations of Blob or Clobs. This article introduces the operations of the Clob field in Mybatis in detail.
1. Introduction to CLOB and BLOB
Both BLOB and CLOB are large field types. (java)
BLOB is stored in binary, while CLOB is able to store text directly. (sql)
Generally, information such as pictures, files, music, etc. is stored in BLOB fields. First convert the file into binary and then store it in. If an article or longer text is used, use CLOB to store the database
The corresponding types of BLOB and CLOB in different databases are also different:
- In MySQL: clob corresponds to text/longtext, blob corresponds to blob
- In Oracle: clob corresponds to clob, blob corresponds to blob
MyBatis provides built-in mapping processing support for CLOB/BLOB type columns. (app)
2. Write Mapper files
As shown below: The id of query sql in the Mapper file is queryByList, and report_summary is a field in the Oracle database, which is of type CLOB.
myClob is a java class. It defines a String-type field reportSummary in the java class to receive CLOB information.
Add the following configuration to read CLOB and BLOB types of data
jdbcType="CLOB" typeHandler="" jdbcType="BLOB" typeHandler=""
<select parameterType="Map" resultMap="queryBaseResultMap"> select id ,title,type,report_summary,author from my_clob where 1 = 1 order by ${orderByClause} </select> <resultMap type="" > <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=""> </resultMap>
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.