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