Mybatis-Note
2018-02-06
Mybatis
mybatis 中批量可选择性的
update不同table中的data方法:
前端传入表名 和
List<LinkedHashMap>类型的valueList1
2private String category;
private List<LinkedHashMap> itemList;中台根据不同的表名调用不同
mapper类的update语句在
mappers包中的对应xml中编写update语句模板1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20<update id="updateListSelective" parameterType="java.util.List" >
<foreach collection="listOfUpdate" index="index" item="item" separator=";">
update counter_item
<set>
<if test="item.price != null">
price = #{item.price,jdbcType=DECIMAL},
</if>
<if test="item.count != null">
count = #{item.count,jdbcType=INTEGER},
</if>
<if test="item.advisePrice != null">
advise_price = #{item.advisePrice,jdbcType=DECIMAL},
</if>
</set>
where
counter_id = #{item.counterId,jdbcType=INTEGER}
and
barcode = #{item.barcode,jdbcType=VARCHAR}
</foreach>
</update>注意:
parameterType为List,<foreach>标签中的字段前面要加列表内容名(即item),mybatis会自动识别List<LinkedHashMap>中的字段
- Mybatis 中 collection 中 List 的默认值为: list