mapping文件的编写(以及实体类与xml中类型的对应关系)

注意事项(1):
实体类 - 数据库 — xml(jdbc)
Integer – int – INTEGER
Float – float– REAL
Byte –tinyint– TINYINT
Long –bigint– BIGINT
String – varchar–VARCHAR

mapping的代码如下:
缺少的对应字段可以自己加上:



<mapper namespace="com.idorabox.manage.dao.jd.JdTokenDao" >
  <resultMap id="BaseResultMap" type="com.idorabox.entity.JdToken" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="token" property="token" jdbcType="VARCHAR" />
    <result column="create_date_time" property="createDateTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
  resultMap>
  <sql id="Base_Column_List" >
    id, token, create_date_time, update_time
  sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from tbl_jd_token
    where id = #{id,jdbcType=INTEGER}
  select>
  <select id="queryList" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from tbl_jd_token
  select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from tbl_jd_token
    where id = #{id,jdbcType=INTEGER}
  delete>
  <insert id="insertSelective" parameterType="com.idorabox.entity.JdToken" >
    insert into tbl_jd_token
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      if>
      <if test="token != null" >
        token,
      if>
      <if test="createDateTime != null" >
        create_date_time,
      if>
      <if test="updateTime != null" >
        update_time,
      if>
    trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      if>
      <if test="token != null" >
        #{token,jdbcType=VARCHAR},
      if>
      <if test="createDateTime != null" >
        #{createDateTime,jdbcType=TIMESTAMP},
      if>
      <if test="updateTime != null" >
        #{updateTime,jdbcType=TIMESTAMP},
      if>
    trim>
  insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.idorabox.entity.JdToken" >
    update tbl_jd_token
    <set >
      <if test="token != null" >
        token = #{token,jdbcType=VARCHAR},
      if>
      <if test="createDateTime != null" >
        create_date_time = #{createDateTime,jdbcType=TIMESTAMP},
      if>
      <if test="updateTime != null" >
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      if>
    set>
    where id = #{id,jdbcType=INTEGER}
  update>
mapper>

你可能感兴趣的:(mapping文件)