当前位置:首页 > 开发 > 编程语言 > Spring > 正文

springMVC+mybatits中mapper配置文件使用

发表于: 2015-03-18   作者:843977358   来源:转载   浏览:
摘要: 1.配置文件resultMap <resultMap id="RepliesMap" type="com.gcj.entity.ArtificialInquiryReply"> <id column="airId" property="id" jdbcType="INTEGER&qu

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> 

 

springMVC+mybatits中mapper配置文件使用

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
 1 与mybatis集成时需要的jar ehcache-core-2.6.5.jar mybatis-ehcache-1.0.2.jar Mybatis、日
在MS官网找到PackageMapper,对其好奇,拿下来体验了一下。 详情:http://code.msdn.microsoft.com/
在Javaweb开发中会经常把一些信息放到配置文件中(*.properties)让程序来加载,在mule中也可以使用
  以前再看视频的时候发现人家连接数据的时候用到了配置文件,所以自己敲机房重构版的时候也 试着
Mybatis中配置Mapper的方法 在这篇文章中我主要想讲一下Mybatis配置文件中mappers元素的配置。关于
Mybatis中配置Mapper的方法 在这篇文章中我主要想讲一下Mybatis配置文件中mappers元素的配置。关于
Mybatis中配置Mapper的方法 在这篇文章中我主要想讲一下Mybatis配置文件中mappers元素的配置。关于
Mybatis中配置Mapper的方法 在这篇文章中我主要想讲一下Mybatis配置文件中mappers元素的配置。关于
Mybatis中配置Mapper的方法 在这篇文章中我主要想讲一下Mybatis配置文件中mappers元素的配置。关于
Mybatis中配置Mapper的方法 在这篇文章中我主要想讲一下Mybatis配置文件中mappers元素的配置。关于
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号