springMVC+mybatits中mapper配置文件使用

1.配置文件resultMap

<resultMap id="RepliesMap" type="com.gcj.entity.ArtificialInquiryReply">
		<id column="airId" property="id" jdbcType="INTEGER" />
		<result column="user_id" property="userId" jdbcType="INTEGER" />
		<result column="created_at" property="createdAt" jdbcType="TIMESTAMP" />
		<result column="updated_at" property="updatedAt" jdbcType="TIMESTAMP" />
		<result column="note" property="note" jdbcType="VARCHAR" />
		<result column="inquiry_user_id" property="inquiryUserId" jdbcType="BIGINT" />
		<result column="answer_time" property="answerTime" jdbcType="TIMESTAMP" />
		<result column="materials_type" property="materialsType" jdbcType="VARCHAR" />
		<!-- 关联 -->
		<association property="bill" javaType="com.gcj.entity.ArtificialInquiryBill" resultMap="BillsMap" />
	</resultMap>

 2.set与if标签嵌套

<update id="updateQuotedPrices" parameterType="com.gcj.entity.ArtificialInquiryQuotedPrices">  
    update artificial_inquiry_quoted_prices  
    <set>  
        <if test="companyId != null and companyId != ''">  
            company_id=#{companyId,jdbcType=INTEGER},  
        </if>  
        <if test="price != null and price != ''">  
            price=#{price,jdbcType=DOUBLE},  
        </if>  
        <if test="remarks != null and remarks != ''">  
            remarks=#{remarks,jdbcType=DOUBLE},  
        </if>  
        <if test="discount != null and discount != ''">  
            discount=#{discount,jdbcType=DOUBLE},  
        </if>  
        <if test="status != null and status != ''">  
            status=#{status,jdbcType=VARCHAR},  
        </if>  
        <if test="reply != null and reply != ''">  
            artificial_inquiry_reply_id=#{reply.id,jdbcType=VARCHAR},  
        </if>  
        <if test="createdAt != null and createdAt != ''">  
            created_at=#{createdAt,jdbcType=VARCHAR},  
        </if>  
        <if test="updatedAt != null and updatedAt != ''">  
            updated_at=#{updatedAt,jdbcType=VARCHAR},  
        </if>  
        <if test="TrackTime != null and TrackTime != ''">  
            inquiry_track_time=#{TrackTime,jdbcType=VARCHAR},  
        </if>  
        <if test="content != null and content != ''">  
            content=#{content,jdbcType=VARCHAR},  
        </if>  
        <if test="userId != null and userId != ''">  
            user_id=#{userId,jdbcType=VARCHAR},  
        </if>  
        <if test="bill != null and bill != ''">  
            artificial_inquiry_bill_id=#{bill.id,jdbcType=VARCHAR},  
        </if>  
        <if test="materialsRemark != null and materialsRemark != ''">  
            materials_remark=#{materialsRemark,jdbcType=VARCHAR},  
        </if>  
    </set>  
    where id=#{id}  
</update> 

 3.批量查询

<select id="getRepliesBatch" resultMap="RepliesMap">  
        select aib.id as aidId,aib.bill_number,  
            air.id as airId,air.material_name,air.specification,air.amount,air.unit,air.other_note,air.brand  
        from artificial_inquiry_replies air, artificial_inquiry_bills aib  
        where air.artificial_inquiry_bill_id = aib.id and air.user_id = 1 and  
            air.status = 'DISPOSE' and air.id in  
        <foreach collection="list" item="id" index="index" open="("  
            close=")" separator=",">  
            #{id}  
        </foreach>  
         order by air.answer_time asc  
    </select> 

 4. 批量增加

<insert id="addReplies" parameterType="list">  
        insert into  
        artificial_inquiry_replies(material_name,specification,amount,unit,artificial_inquiry_bill_id,user_id,status,created_at,updated_at,  
            note,inquiry_user_id,no_pass_reason,other_note,is_front,brand,answer_time,materials_type)  
        values  
        <foreach collection="list" item="reply" index="index" separator=",">  
            (  
                #{reply.materialName},#{reply.specification},#{reply.amount},  
                #{reply.unit},#{reply.bill.id},#{reply.userId},#{reply.status},  
                #{reply.createdAt},#{reply.updatedAt},#{reply.note},#{reply.inquiryUserId},  
                #{reply.noPassReason},#{reply.otherNote},#{reply.front},#{reply.brand},  
                #{reply.answerTime},#{reply.materialsType}  
            )  
        </foreach>  
    </insert>

 5.  批量删除

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

 

你可能感兴趣的:(set与If嵌套,resultMap,批量删除,批量查询,批量增加)