使用jpa中的group by返回一个数组对象

前言

在jpa中,使用grouo by返回一个数组对象

对象接收

1、定义一个实体类

less 复制代码
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OperatorStatistics {

    private Long id;

    private Long count;

}

hsql写法为:

less 复制代码
@Query(value = "select OperatorStatistics(m.operatorId, count(*)) from MachineRoom m where m.operatorId in ?1 group by m.operatorId")
List<OperatorStatistics> getMachineRoomCountByOperatorIds(@Param("operatorIds") List<Long> operatorIds);

否则group by 返回的是一个List<Object[]>数组

总结

可以jpa中的group by返回一个数组对象,根据自己需要返回值取

相关推荐
一点程序10 小时前
基于SpringBoot的选课调查系统
java·spring boot·后端·选课调查系统
启山智软12 小时前
【中大企业选择源码部署商城系统】
java·spring·商城开发
奋进的芋圆12 小时前
Spring Boot 实现三模安全登录:微信扫码 + 手机号验证码 + 邮箱验证码
spring boot·redis·微信
怪兽源码12 小时前
基于SpringBoot的选课调查系统
java·spring boot·后端·选课调查系统
csdn_aspnet13 小时前
ASP.NET Core 中的依赖注入
后端·asp.net·di·.net core
昊坤说不出的梦13 小时前
【实战】监控上下文切换及其优化方案
java·后端
疯狂踩坑人14 小时前
【Python版 2026 从零学Langchain 1.x】(二)结构化输出和工具调用
后端·python·langchain
m0_7400437315 小时前
【无标题】
java·spring boot·spring·spring cloud·微服务
重整旗鼓~15 小时前
1.外卖项目介绍
spring boot
橘子师兄15 小时前
C++AI大模型接入SDK—ChatSDK封装
开发语言·c++·人工智能·后端