Java queryWrapper groupby自定义字段
String sql = "data_id,(select value from lz_html a where a.data_id = lz_html.data_id and class_name='test-item-status') status," +
"(select value from lz_html a where a.data_id = lz_html.data_id and class_name='test-item-duty-person') dutyPerson," +
"(select value from lz_html a where a.data_id = lz_html.data_id and class_name='test-item-tag') tag," +
"(select value from lz_html a where a.data_id = lz_html.data_id and class_name='test-item-level') level," +
"(select value from lz_html a where a.data_id = lz_html.data_id and class_name='test-item-verno') verNo";
queryWrapper.select(sql);
queryWrapper.groupBy("data_id"); // 根据group字段进行分组
List<Map>转List<Entity>
List<TestItemModel> newList = JSON.parseObject(JSON.toJSONString(resultList), new TypeReference<List<TestItemModel>>() {});
连在一起看
QueryWrapper<LzHtml> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("file_id", filter.getFileId());
queryWrapper.in("data_id", datas);
String sql = "data_id,(select value from lz_html a where a.data_id = lz_html.data_id and class_name='test-item-status') status," +
"(select value from lz_html a where a.data_id = lz_html.data_id and class_name='test-item-duty-person') dutyPerson," +
"(select value from lz_html a where a.data_id = lz_html.data_id and class_name='test-item-tag') tag," +
"(select value from lz_html a where a.data_id = lz_html.data_id and class_name='test-item-level') level," +
"(select value from lz_html a where a.data_id = lz_html.data_id and class_name='test-item-verno') verNo";
queryWrapper.select(sql);
queryWrapper.groupBy("data_id"); // 根据group字段进行分组
List<Map<String, Object>> resultList = lzHtmlService.listMaps(queryWrapper);
//List<Map>转List<Entity>
List<TestItemModel> newList = JSON.parseObject(JSON.toJSONString(resultList), new TypeReference<List<TestItemModel>>() {});