版權聲明:本文為博主原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接和本聲明。
本文鏈接:https://blog.csdn.net/bisal/article/details/82775403
Java項目涉及到數據庫交互,以往常用的是JDBC,現在則有Hibernate、Mybatis等這些持久化支持。
本文鏈接:https://blog.csdn.net/bisal/article/details/82775403
Java項目涉及到數據庫交互,以往常用的是JDBC,現在則有Hibernate、Mybatis等這些持久化支持。
項目中用到了MyBatis,和JDBC最顯著的區別,就是SQL語句配置化,通過xml文件定義SQL語句,當然JDBC也可以將SQL配置化,需要定制開發,MyBatis則直接支持這種方法。
官方對於MyBatis的介紹,
MyBatis is a first class persistence framework with support for custom SQL, stored procedures and advanced mappings. MyBatis eliminates almost all of the JDBC code and manual setting of parameters and retrieval of results. MyBatis can use simple XML or Annotations for configuration and map primitives, Map interfaces and Java POJOs (Plain Old Java Objects) to database records.
簡單來講,MyBatis幾乎屏蔽了所有JDBC代碼,用一種簡單的xml,或者注解,就能完成數據庫交互。
xml配置文件,可用MyBatis自己定義的數據類型,引自:http://www.mybatis.org/mybatis-3/configuration.html
Associated JDBC type can be specified by two means:
Adding a jdbcType attribute to the typeHandler element (for example: jdbcType="VARCHAR").
Adding a @MappedJdbcTypes annotation to your TypeHandler class specifying the list of JDBC types to associate it with. This annotation will be ignored if the jdbcType attribute as also been specified.
例如下面的配置,指定companyid參數類型為BIGINT,
<select id='getMeetingnoByCompanyid' parameterType="java.lang.Integer"
resultType="java.lang.String">
select a.meetingno
from xxx a
where a.companyid = #{companyid, jdbcType=BIGINT}
</select>
對於jdbcType,MyBatis的API文檔有說明,引自:http://www.mybatis.org/mybatis-3/apidocs/reference/org/apache/ibatis/type/JdbcType.html
另外,這篇文章,給出了JdbcType和Oracle以及MySQL,相互之間的映射關系,比較詳細,引自:http://blog.csdn.net/loongshawn/article/details/50496460
JdbcType
Oracle
MySql
JdbcType
ARRAY
JdbcType
BIGINT
BIGINT
JdbcType
BINARY
JdbcType
BIT
BIT
JdbcType
BLOB
BLOB
BLOB
JdbcType
BOOLEAN
JdbcType
CHAR
CHAR
CHAR
JdbcType
CLOB
CLOB
修改為TEXT
JdbcType
CURSOR
JdbcType
DATE
DATE
DATE
JdbcType
DECIMAL
DECIMAL
DECIMAL
JdbcType
DOUBLE
NUMBER
DOUBLE
JdbcType
FLOAT
FLOAT
FLOAT
JdbcType
INTEGER
INTEGER
INTEGER
JdbcType
LONGVARBINARY
JdbcType
LONGVARCHAR
LONG VARCHAR
JdbcType
NCHAR
NCHAR
JdbcType
NCLOB
NCLOB
JdbcType
NULL
JdbcType
NUMERIC
NUMERIC/NUMBER
NUMERIC/
JdbcType
NVARCHAR
JdbcType
OTHER
JdbcType
REAL
REAL
REAL
JdbcType
SMALLINT
SMALLINT
SMALLINT
JdbcType
STRUCT
JdbcType
TIME
TIME
JdbcType
TIMESTAMP
TIMESTAMP
TIMESTAMP/DATETIME
JdbcType
TINYINT
TINYINT
JdbcType
UNDEFINED
JdbcType
VARBINARY
JdbcType
VARCHAR
VARCHAR
VARCHAR
文章最后發布於: 2018-09-19 17:25:53
————————————————
版權聲明:本文為CSDN博主「bisal」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/bisal/article/details/82775403