需求:查出给定id的记录: <select id="getEmpsByConditionForeach" resultType="com.test.beans.Employee"> SELECT * FROM tb1_emplyee WHERE id IN <foreach collection="list" item="item_id" separator="," open="…
Sql中可将重复的sql提取出来,使用时用include引用即可,最终达到sql重用的目的,如下: <select id="findUserByNameAndSex" parameterType="com.huida.po.User" resultType="com.huida.po.User"> <!-- select * from user where 1=1 and username like "%${usern…
向sql传递数组或List,mybatis使用foreach解析,如下: 需求: 传入多个id查询用户信息,用下边的sql实现: select * from user where id in(1,10,24); 1.在QueryVo类中定义: private List<Integer> ids; public List<Integer> getIds() { return ids; } 2.在UserMapper接口中定义方法: public List<User> fi…