继续潜水

导航

 

在mybatis  传入数组在sql语句中进行查询

1.传入一个map集合,已或者的形式拼接数组循环

<select id="selectUserByList" parameterClass="HashMap" resultClass="UserInfo">
      select * from user
        <dynamic prepend="WHERE">
            <isNotNull property="userId">
                <iterate property="userId" conjunction=" or " close=")" open="("> 
                    userId = #userId[]# 
                </iterate>
            </isNotNull>
        </dynamic>
</select>

2.1.传入一个map集合,使用in() 关键字

 

<delete id="del" parameterClass="HashMap">
    DELETE FROM user WHERE  userId  in
    <iterate property="userIds" conjunction="," open="(" close=")">
        #userIds[]#
    </iterate>
  </delete>

 

 

批量插入数据

<!-- addSerialNumbers 添加流水号     select fn_sys_max('itk_ticket2') -->
   <insert id="addSerialNumbers"  parameterClass="java.util.List">
           INSERT into itk_ticket2 
        (tkt_id,tkt_code,tkt_name,tkt_amt,START_DATE,END_DATE,CREATED_USERID,CREATED_USERNAME,CREATED_TIME) 
        VALUES 
           <dynamic>
            <iterate conjunction=",">
                 ((select fn_sys_max('itk_ticket2'))
                 ,#comList[].tktCode#
                 ,#comList[].tktName#
                 ,#comList[].tktAmt#
                 ,#comList[].startDate#
                 ,#comList[].endDate#
                 ,#comList[].createdUserId#
                 ,#comList[].createdUserName#
                 ,now()
                 )
             </iterate>
        </dynamic>
   </insert>

 

posted on 2015-08-31 15:08  继续潜水  阅读(1478)  评论(0编辑  收藏  举报