原创

springMVC+mybatis中mapper配置文件使用

温馨提示:
本文最后更新于 2016年11月19日,已超过 2,942 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我

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>   


正文到此结束
本文目录