QueryWrapper
eq
根据Id返回List
//根据条件查询一条数据,多了会报错 public R<Family> queryMemberId(String meberId) { Family family = familyService.getOne(new QueryWrapper<Family>().eq("member_id", meberId)); return R.data(family); } //根据指定条件返回list public R<List<Family>> treeList(String book_id) { List<Family> familyList = familyService.list(new QueryWrapper<Family>().eq("book_id", book_id)); return R.data(buildTree(familyList)); }
select
//查询指定列,返回list public R<List<Family>> select() { List<Family> list = familyService.list(new QueryWrapper<Family>().select("id", "name")); return R.data(list); }
返回JSON对象
使用eq条件查询
public R<JSONObject> listByFamily(Long id) { JSONObject jsonObject = new JSONObject(); Family family = familyService.getById(id); //将第一个表中的数据存储到json中 jsonObject.set("family", family); List<Deed> list = deedService.list(new QueryWrapper<Deed>().eq("family_id", id)); //将第二个表中的数据存储到json中 jsonObject.set("list", list); return R.data(jsonObject); }