基本概念
WHERE id=1 OR id=10 OR id=16
在查询条件中,查询条件定义成一个sql片段,需要修改sql片段
如图所示
案例:
1.创建测试类
@Test
public void findUserList() throws Exception{
SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtil.getSqlSessionFactory();
SqlSession session = sqlSessionFactory.openSession();
UserMapper mapper = session.getMapper(UserMapper.class);
UserQueryVo queryVo = new UserQueryVo();
UserCustomer customer = new UserCustomer();
queryVo.setCustomer(customer);
List
ids.add(1);
ids.add(10);
ids.add(22);
queryVo.setIds(ids);
List
for (UserCustomer userCustomer : list) {
System.out.println(userCustomer.getId()+":"+userCustomer.getUsername());
}
session.close();
}
2.创建UserQueryVo
public class UserQueryVo {
//传递多个id
private List
//在这里包装查询条件(用户查询条件)
/*private User user;*/
private UserCustomer customer;
set get 省
}
public class UserCustomer extends User {
//在这里面进行扩展用户信息
}
public class User implements Serializable {
private int id;
private String username;
private Date birthday;
private String sex;
private String address;
//添加订单属性
private List
set get 省
3. UserMapper
public interface UserMapper {
//用户信息综合查询列表
public List
}
4.mapper.xml