自学内容网 自学内容网

Java QueryWrapper groupBy自定义字段,以及List<Map>转List<Entity>

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>>() {});


原文地址:https://blog.csdn.net/gdgztt/article/details/145018791

免责声明:本站文章内容转载自网络资源,如侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!