使用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返回一个数组对象,根据自己需要返回值取

相关推荐
BingoGo19 小时前
PHP 8.5 新特性 闭包可以作为常量表达式了
后端·php
SimonKing19 小时前
Komari:一款专为开发者打造的轻量级服务“看守神器”
后端
间彧19 小时前
Spring Security如何解析JWT,并自行构造SecurityContex
后端
疯癫的老码农19 小时前
【Linux环境下安装】SpringBoot应用环境安装(五)-milvus安装
linux·spring boot·milvus
Tech_Lin19 小时前
前端工作实战:如何在vite中配置代理解决跨域问题
前端·后端
间彧19 小时前
在Spring Cloud Gateway中如何具体实现JWT验证和用户信息提取?
后端
间彧19 小时前
SecurityContext在分布式系统(如微服务)中如何传递?有哪些常见方案?
后端
孤廖19 小时前
C++ 模板再升级:非类型参数、特化技巧(含全特化与偏特化)、分离编译破解
linux·服务器·开发语言·c++·人工智能·后端·深度学习
林希_Rachel_傻希希19 小时前
Express 入门全指南:从 0 搭建你的第一个 Node Web 服务器
前端·后端·node.js