mybatisplus使用@Select
程序员文章站
2024-03-02 13:01:10
...
dao文件下
@Select("SELECT DISTINCT name FROM `ck` where company = '顺网' and deleted = 1")
List<CkEntity> listCompany(QueryWrapper<CkEntity> wrapper);
@Select("SELECT count(*) FROM `ck` where company = '顺网' and deleted = 1" + " and name like '%${name}%'")
String countCompanyData(@Param("name") String name);
在 server接口中新建一个方法
HashMap<String, Object> listCompanyData();
实现方法
@Override
public HashMap<String, Object> listCompanyData() {
QueryWrapper<CkEntity> queryWrapper = new QueryWrapper<>();
List<CkEntity> ckEntities = ckDao.listCompany(queryWrapper);
ArrayList<String> data = new ArrayList<> ();
for (CkEntity s: ckEntities) {
data.add(s.getName());
}
List<HashMap<String, String>> name = data.stream().map((i) -> {
HashMap<String ,String > data1 = new HashMap<>();
data1.put("name", i);
String s1 = ckDao.countCompanyData(i);
data1.put("value", s1);
return data1;
}).collect(Collectors.toList());
HashMap<String, Object> companyData = new HashMap<>();
companyData.put("children", name);
companyData.put("name","顺网");
companyData.put("value",137);
HashMap<String, Object> companyDatas = new HashMap<>();
companyDatas.put("name","顺网");
//map.values.toArray() map变数组
ArrayList<HashMap<String, Object>> datas = new ArrayList<>();
datas.add(companyData);
companyDatas.put("children", datas);
return companyDatas;
}
CkController 实现接口
@RequestMapping("/company")
public List<Object> company(@RequestParam Map<String, Object> params){
HashMap<String, Object> companyData = ckService.listCompanyData();
ArrayList<Object> data = new ArrayList<> ();
data.add(companyData);
return data;
}
上一篇: Android View事件分发机制详解