mybatis批量查询,批量新增就不聊了,今天看看批量修改。
直接上代码吧
xml文件中代码如下:
<update id="batchUpdate" parameterType="java.util.List">
update pat_doc_pat_info set
sex=
<foreach collection="list" item="item" index="index" separator=" " open="case patient_id" close="end">
when #{item.patientId} then #{item.sex}
</foreach>
,address=
<foreach collection="list" item="item" index="index" separator=" " open="case patient_id" close="end">
when #{item.patientId} then #{item.address}
</foreach>
,birth_time=
<foreach collection="list" item="item" index="index" separator=" " open="case patient_id" close="end">
when #{item.patientId} then #{item.birthTime}
</foreach>
,remark=
<foreach collection="list" item="item" index="index" separator=" " open="case patient_id" close="end">
when #{item.patientId} then #{item.remark}
</foreach>
,modified_time = now()
,belong_hospital = 1
where delete_flag = 1
and doctor_id =
<foreach collection="list" item="item" index="index" separator=" " open="case patient_id" close="end">
when #{item.patientId} then #{item.doctor_id}
</foreach>
and patient_id in
<foreach collection="list" index="index" item="item" separator="," open="(" close=")">
#{item.patientId}
</foreach>
</update>
mapper类中代码如下:
int batchUpdate(List<PICAPPatientModel> list);
测试类方法如下:
@Autowired
private PatDocPatInfoMapper patDocPatInfoMapper;
@Test
public void testMapperMethod () {
List<PICAPPatientModel> updateMappingList = new ArrayList<>();
PICAPPatientModel model1 = new PICAPPatientModel();
model1.setPatientId(12334);
model1.setDoctor_id(5466927);
model1.setSex(2);
model1.setAddress("上海市普陀区xxxx");
model1.setBirthTime(new Date());
model1.setRemark("哈哈哈哈");
PICAPPatientModel model2 = new PICAPPatientModel();
model2.setPatientId(5923302);
model2.setDoctor_id(5466927);
model2.setSex(1);
model2.setAddress("上海市普陀区xxxx金沙江路1008号");
model2.setBirthTime(new Date());
model2.setRemark("哈哈哈哈adsfsa");
updateMappingList.add(model1);
updateMappingList.add(model2);
patDocPatInfoMapper.batchUpdate(updateMappingList);
}