您好,登錄后才能下訂單哦!
這篇文章主要講解了“怎么理解MyBatis中的JdbcType映射”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“怎么理解MyBatis中的JdbcType映射”吧!
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 |
感謝各位的閱讀,以上就是“怎么理解MyBatis中的JdbcType映射”的內容了,經過本文的學習后,相信大家對怎么理解MyBatis中的JdbcType映射這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。