原创

springMVC+mybatis中mapper配置文件使用

1.配置文件resultMap

<resultMap id="XXMap" type="实体类路径">  
    <id column="airId" property="id" jdbcType="INTEGER" />    
    <result column="dateField" property="createdAt" jdbcType="TIMESTAMP" />  
    <result column="stringField" property="note" jdbcType="VARCHAR" />  
    <result column="longField" property="inquiryUserId" jdbcType="BIGINT" />   
    <!-- 关联 -->  
    <association property="对应属性名" javaType="实体类路径" resultMap="YYMap" />  
</resultMap> 

 2.set与if标签嵌套

<update id="update" parameterType="XX">    
    update table a
    <set>    
        <if test="id!= null and id!= ''">    
            a.id=#{id,jdbcType=INTEGER},    
        </if>     
    </set>    
    where a.id=#{id}    
</update>  

 3.批量查询

<select id="getXX" resultMap="xxMap">    
    select *   
    from table t
       t.id in    
		<foreach collection="list" item="id" index="index" open="(" close=")" separator=",">    
            #{id}    
        </foreach>     
</select>   

 4. 批量增加

<insert id="insert" parameterType="list">    
	insert into table t
	values    
	<foreach collection="list" item="reply" index="index" separator=",">    
		(    
			#{t.id} 
		)    
	</foreach>    
</insert>  

 5.  批量删除

<delete id="delete" parameterType="list">    
  delete from table t 
  where id in    
  <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">    
	  #{item}    
  </foreach>    
</delete>   


正文到此结束