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

Java queryWrapper groupby自定义字段

java 复制代码
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>

java 复制代码
List<TestItemModel> newList = JSON.parseObject(JSON.toJSONString(resultList), new TypeReference<List<TestItemModel>>() {});

连在一起看

java 复制代码
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>>() {});
相关推荐
王先生技术栈15 分钟前
思维导图,Android版本实现
java·前端
生如夏花℡17 分钟前
JAVA学习记录3
java·学习·idea
{⌐■_■}22 分钟前
【gRPC】对称与非对称加解密和单向TLS与双向TLS讲解与go案例
java·servlet·golang
敲代码养活全家41 分钟前
ElasticsearchJavaClient工具类分析
java·elasticsearch·搜索引擎
蟹黄堡在逃员工1 小时前
消息队列MQ(一)
java·后端
栗豆包1 小时前
w148基于spring boot的文档管理系统的设计与实现
java·spring boot·后端·spring·tornado
一直学习永不止步1 小时前
LeetCode题练习与总结:随机翻转矩阵--519
java·数学·算法·leetcode·哈希表·水塘抽样·随机化
伤魂孤傲1 小时前
强制关闭Redis快照导致不能持久化
java·redis
xiao--xin2 小时前
LeetCode100之组合总和(39)--Java
java·开发语言·算法·leetcode·回溯
好像是个likun2 小时前
Nacos注册中心微服务注册
java·运维·微服务