您的位置:首页 > 其它

MyBatis 中 批量操作如查询

2016-03-07 16:42 459 查看
实例:根据订单号进行多了查询

定义domain

public class orders{
public String orderId; //订单号
****
**
public String[] orderIds; //用来存储多个订单号,批量操作时使用
</pre><pre code_snippet_id="1600467" snippet_file_name="blog_20160307_7_9103556" name="code" class="java">public void setOrderId(String orderId) { //每次前台页面填写完毕自动添加到数组中
this.orderId = orderId;
if((StringUtils.isNotBlank(this.orderId))&&this.orderId.contains(","))
this.orderIds =this.orderId.split(",");
}
}

其它各层不用动,

在xml 中修改,即可

<select id="queryOrdersListWithPage" resultMap="OrdersMap"
parameterType="com.letv.uos.domain.query.OrdersQuery">
select <include refid="ordersColumns"/> from orders where <include refid="queryOrdersListWhere"/>
<if test="orderIds != null and orderIds != ''">
and order_id in
<foreach collection="orderIds" item="item" index="index" open="("  separator="," close=")">
#{item}
</foreach>
</if>
order by create_time desc
limit #{startIndex},#{pageSize}
</select>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: