说明:
1、Example类仅支持单表查询,对于联表查询,尚无方法,需要自己在mybatis里面写接口和xml,根据具体的sql语句去查询。
2、泛型里面的类就是被查表的具体实体类,且new Example(实体类.class);
3、dao层必须继承基础Mapper<被查实体类>,才能用里面的方法,也可以自己拓展方法。
举例如下:
1)、
@Override
public List<LibraryCatalog> list() {
Example example = new Example(LibraryCatalog.class);
example.createCriteria().andEqualTo("useStatus", true);
example.orderBy("orderNum");
List<LibraryCatalog> libraryCatalogs = libraryCatalogMapper.selectByExample(example);
return libraryCatalogs;
}
2)、
@Override
public LibraryProductBrand findOne(String id) {
Example example = new Example(LibraryProductBrand.class);
example.createCriteria().andEqualTo("id", id)
.andEqualTo("useStatus", false);
return libraryProductBrandMapper.selectOneByExample(example);
}
3)、
@Override
public PageInfo<LibraryProductBrand> list(Integer pageNum, Integer pageSize, LibraryProductBrand libraryProductBrand) {
//查询所有未被删除的商品品牌
if (pageNum != null && pageSize != null) {
PageHelper.startPage(pageNum, pageSize);
}
Example example = PageDataConvert.getWhere(libraryProductBrand);
example.and().andEqualTo("useStatus", false);
example.orderBy("createTime").desc();
return new PageInfo<>(libraryProductBrandMapper.selectByExample(example));
}