批量添加
int addDepartmentList(List<DepartmentPO> list);
insert into t_department (
department_id, department_name,department_desc,hospital_id,insert_dt,update_dt)
values
<foreach collection ="list" item="department" index= "index" separator =",">
(
#{department.departmentId},
#{department.departmentName},
#{department.departmentDesc},
#{department.hospitalId},
#{department.insertDt},
#{department.updateDt}
)
</foreach >
批量修改
int updateDepartmentList(List<DepartmentPO> list);
<foreach collection ="list" item="department" index= "index" separator =";">
UPDATE t_department
SET department_name = #{department.departmentName}, update_dt = #{department.updateDt}, department_desc = #{department.departmentDesc}
WHERE department_id = #{department.departmentId}
</foreach >
in/or 操作优化(mysql)
原始查询
select * from user where age > 30 or age < 18
优化后查询
select * from user where (age > 30) + (age < 18) > 0
原始查询
select * from t_department where department_id in ('0','1')
优化后查询
select * from t_department where (department_id = 0) + (department_id = 1) > 0
mybatis 实现 in操作优化
List<DepartmentPO> listDepartmentByIds(List<String> ids);
select * from t_department
<where>
<foreach collection ="ids" item="id" index= "index" separator ="+">
(department_id = #{id})
</foreach >
> 0
</where>
<foreach collection ="ids" item="id" index= "index" separator ="UNION">
select * from t_doctor where id = #{id}
</foreach >
网友评论