Mybatis中javaType和jdbcType对应和CRUD例子

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mybatis.config.InfoDao">
 <resultMap type="java.util.Map" id="resultjcm">
  <result property="FLD_NUMBER" column="FLD_NUMBER"  javaType="double" jdbcType="NUMERIC"/>
  <result property="FLD_VARCHAR" column="FLD_VARCHAR" javaType="string" jdbcType="VARCHAR"/>
  <result property="FLD_DATE" column="FLD_DATE" javaType="java.sql.Date" jdbcType="DATE"/>
  <result property="FLD_INTEGER" column="FLD_INTEGER"  javaType="int" jdbcType="INTEGER"/>
  <result property="FLD_DOUBLE" column="FLD_DOUBLE"  javaType="double" jdbcType="DOUBLE"/>
  <result property="FLD_LONG" column="FLD_LONG"  javaType="long" jdbcType="INTEGER"/>
  <result property="FLD_CHAR" column="FLD_CHAR"  javaType="string" jdbcType="CHAR"/>
  <result property="FLD_BLOB" column="FLD_BLOB"  javaType="[B" jdbcType="BLOB" />
  <result property="FLD_CLOB" column="FLD_CLOB"  javaType="string" jdbcType="CLOB"/>
  <result property="FLD_FLOAT" column="FLD_FLOAT"  javaType="float" jdbcType="FLOAT"/>
  <result property="FLD_TIMESTAMP" column="FLD_TIMESTAMP"  javaType="java.sql.Timestamp" jdbcType="TIMESTAMP"/>
 </resultMap>

 <select id="selectAll" parameterType="map" resultMap="resultjcm">
  select * from JCM
 </select>

 <insert id="insertInfo" parameterType="map">
  insert into jcm
  values
  (
  #{FLD_NUMBER,jdbcType=INTEGER},
  #{FLD_VARCHAR,jdbcType=VARCHAR},
  #{FLD_DATE,jdbcType=DATE},
  #{FLD_INTEGER,jdbcType=INTEGER},
  #{FLD_DOUBLE,jdbcType=DOUBLE},
  #{FLD_LONG,jdbcType=INTEGER},
  #{FLD_CHAR,jdbcType=CHAR},
  #{FLD_BLOB,jdbcType=BLOB},
  #{FLD_CLOB,jdbcType=CLOB},
  #{FLD_FLOAT,jdbcType=FLOAT},
  #{FLD_TIMESTAMP,jdbcType=TIMESTAMP}
  )
 </insert>

 <select id="selectOne" resultMap="resultjcm">
  select * from jcm where
  FLD_NUMBER=#{FLD_NUMBER,jdbcType=INTEGER}
 </select>

 <delete id="delectOne" parameterType="map">
  delete from jcm
  where
  FLD_NUMBER=#{FLD_NUMBER,jdbcType=INTEGER}
 </delete>

 <update id="updateOne" parameterType="map">
  update jcm  set
  FLD_VARCHAR=#{FLD_VARCHAR,jdbcType=VARCHAR},FLD_DATE=#{FLD_DATE,jdbcType=DATE},FLD_INTEGER=#{FLD_INTEGER,jdbcType=INTEGER}   where
  FLD_NUMBER=#{FLD_NUMBER,jdbcType=INTEGER}
 </update>

</mapper>

 

节选自:http://blog.sina.com.cn/s/blog_4a456e6a0100vse0.html

你可能感兴趣的:(mybatis)