Mybatis中javaType和jdbcType对应关系及案例

[html]   view plain  copy
  1. xml version="1.0" encoding="UTF-8" ?>  
  2. >  
  3. <mapper namespace="com.mybatis.config.InfoDao">  
  4. <resultMap type="java.util.Map" id="resultjcm">  
  5. <result property="FLD_NUMBER" column="FLD_NUMBER" javaType="double" jdbcType="NUMERIC"/>  
  6. <result property="FLD_VARCHAR" column="FLD_VARCHAR" javaType="string" jdbcType="VARCHAR"/>  
  7. <result property="FLD_DATE" column="FLD_DATE" javaType="java.sql.Date" jdbcType="DATE"/>  
  8. <result property="FLD_INTEGER" column="FLD_INTEGER" javaType="int" jdbcType="INTEGER"/>  
  9. <result property="FLD_DOUBLE" column="FLD_DOUBLE" javaType="double" jdbcType="DOUBLE"/>  
  10. <result property="FLD_LONG" column="FLD_LONG" javaType="long" jdbcType="INTEGER"/>  
  11. <result property="FLD_CHAR" column="FLD_CHAR" javaType="string" jdbcType="CHAR"/>  
  12. <result property="FLD_BLOB" column="FLD_BLOB" javaType="[B" jdbcType="BLOB"/>  
  13. <result property="FLD_CLOB" column="FLD_CLOB" javaType="string" jdbcType="CLOB"/>  
  14. <result property="FLD_FLOAT" column="FLD_FLOAT" javaType="float" jdbcType="FLOAT"/>  
  15. <result property="FLD_TIMESTAMP" column="FLD_TIMESTAMP" javaType="java.sql.Timestamp" jdbcType="TIMESTAMP"/>  
  16. resultMap>  
  17.   
  18. <select id="selectAll" parameterType="map" resultMap="resultjcm">  
  19. select * from JCM  
  20. select>  
  21.   
  22. <insert id="insertInfo" parameterType="map">  
  23. insert into jcm  
  24. values  
  25. (  
  26. #{FLD_NUMBER,jdbcType=INTEGER},  
  27. #{FLD_VARCHAR,jdbcType=VARCHAR},  
  28. #{FLD_DATE,jdbcType=DATE},  
  29. #{FLD_INTEGER,jdbcType=INTEGER},  
  30. #{FLD_DOUBLE,jdbcType=DOUBLE},  
  31. #{FLD_LONG,jdbcType=INTEGER},  
  32. #{FLD_CHAR,jdbcType=CHAR},  
  33. #{FLD_BLOB,jdbcType=BLOB},  
  34. #{FLD_CLOB,jdbcType=CLOB},  
  35. #{FLD_FLOAT,jdbcType=FLOAT},  
  36. #{FLD_TIMESTAMP,jdbcType=TIMESTAMP}  
  37. )  
  38. insert>  
  39.   
  40. <select id="selectOne" resultMap="resultjcm">  
  41. select * from jcm where  
  42. FLD_NUMBER=#{FLD_NUMBER,jdbcType=INTEGER}  
  43. select>  
  44.   
  45. <delete id="delectOne" parameterType="map">  
  46. delete from jcm  
  47. where  
  48. FLD_NUMBER=#{FLD_NUMBER,jdbcType=INTEGER}  
  49. delete>  
  50.   
  51. <update id="updateOne" parameterType="map">  
  52. update jcm set  
  53. FLD_VARCHAR=#{FLD_VARCHAR,jdbcType=VARCHAR},FLD_DATE=#{FLD_DATE,jdbcType=DATE},FLD_INTEGER=#{FLD_INTEGER,jdbcType=INTEGER} where  
  54. FLD_NUMBER=#{FLD_NUMBER,jdbcType=INTEGER}  
  55. update>  
  56.   
  57. mapper>  

MybatisjavaTypejdbcType对应和CRUD例子

  
  
  
  
  
  
  
  
  
  
  
 

 

 

MybatisjavaTypejdbcType对应关系

 

JDBC Type			Java Type
CHAR				String
VARCHAR				String
LONGVARCHAR			String
NUMERIC				java.math.BigDecimal
DECIMAL				java.math.BigDecimal
BIT				boolean
BOOLEAN				boolean
TINYINT				byte
SMALLINT			short
INTEGER				int
BIGINT				long
REAL				float
FLOAT				double
DOUBLE				double
BINARY				byte[]
VARBINARY			byte[]
LONGVARBINARY		        byte[]
DATE				java.sql.Date
TIME				java.sql.Time
TIMESTAMP			java.sql.Timestamp
CLOB				Clob
BLOB				Blob
ARRAY				Array
DISTINCT			mapping of underlying type
STRUCT				Struct
REF	                        Ref
DATALINK			java.net.URL[color=red][/color]

你可能感兴趣的:(mybatis)