Mybatis批量操作及日期比較等

批量新增

    Java:
    List<OrderPri> orderPris = new ArrayList<OrderPri>();
    orderPris.add(new OrderPri(null,"004", 1, null));
    orderPris.add(new OrderPri(null,"005", 2, null));
    System.out.println(JSON.toJSONString(orderPriMapper.insertBatch(orderPris)))

    xml
    <insert id = "insertBatch">
       insert into order_pri(order_num, is_del)values
    <foreach collection="list" item="it" separator=",">
      (#{it.orderNum, jdbcType = VARCHAR}, #{it.isDel, jdbcType = INTEGER})
    </foreach>

批量更新

根據集合更新某一個字段

Java:
List<OrderPri> orderPris = new ArrayList<OrderPri>();
        orderPris.add(new OrderPri(1,"004", 1, null));
        orderPris.add(new OrderPri(2,"005", 2, null));        System.out.println(JSON.toJSONString(orderPriMapper.updateByIds(orderPris)));

xml:
<update id="updateByIds">
    update order_pri set is_del = 1
    where id in
    <foreach collection="list" separator="," item="it" open="(" close=")">
      #{it.id, jdbcType = INTEGER}
    </foreach>
</update>

比較日期的年月

and DATE_FORMAT(start_date, '%Y-%m') = DATE_FORMAT(#{startDate}, '%Y-%m')

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章