public Example createExample(Brand brand) {
//动态构建条件Example,criteria:动态组装条件
Example example = new Example(Brand.class);
Example.Criteria criteria = example.createCriteria();
//组装条件
if(brand!=null){
//id
if(!StringUtils.isEmpty(brand.getId())){
criteria.andEqualTo("id",brand.getId());
}
if(!StringUtils.isEmpty(brand.getName())){
//1)输入name-根据name查询[模糊查询] select * from tb_brand wehere name like '%brand.getName%'
criteria.andLike("name","%"+brand.getName()+"%");
}
if(!StringUtils.isEmpty(brand.getLetter())){
//2)输入了letter-根据letter查询 select * from tb_brand where letter= 'brand.getLetter'
criteria.andEqualTo("letter",brand.getLetter());
}
}
return example;
}
条件构造器Criteria
最新推荐文章于 2023-03-10 20:57:36 发布