java - Spring Boot JPA - 返回带有列表的自定义对象
问题描述
我正在使用 Spring JpaRepository 开发一个 Spring Boot 应用程序。我正在使用自己的查询返回自定义对象列表,这些对象是具有 ID、名称和团队列表的组。
所以我有这样的事情:
public interface GroupDB {
public Long getId();
public String getName();
public List<TeamDB> getTeams();
}
public interface TeamDB {
public Long getId();
public Long getWon();
public Long getDrawn();
public Long getLost();
public Long getPoints();
}
我的查询返回这个(我试图自己解决我的问题,这就是为什么这里是“团队点......”但这不起作用):
SELECT
id,
name,
team AS "team.id",
SUM(win) AS "team.won",
SUM(draw) AS "team.drawn",
SUM(loss) AS "team.lost",
3*SUM(win)+SUM(draw) AS "team.points"
...
查询非常非常长,但如果你想要它,这里是:https ://pastebin.pl/view/45b082f5
然后我向数据库发出请求。
@Query(value = getGroupsFromGroupsStageQuery, nativeQuery = true)
List<GroupDB> getGroupsFromGroupsStage(@Param("tournament_id") Long tournamentId);
举个例子:
我想得到一组id(8905),名字(“Grupa 65”)和四支球队的名单:id,win,drawn,lost和points。
但我能得到的最好的东西是 4 个组的列表,其中包含 id、名称和null
分配给团队
那么我该怎么做呢?
解决方案
推荐阅读
- python-3.x - 使用 Dataframe.columns 和 Dataframe.keys() 获取列名有什么区别吗?
- apache-spark - 有没有办法清除齐柏林飞艇的记忆?
- java - 如何在 Selenium Web 驱动程序中处理带有空白目标的链接
- amazon-web-services - 如何使用 boto3 sdk 启用 s3 服务器访问日志记录?
- excel - 如何将excel嵌入图像复制到特定单元格表格中的单词标题?
- c++ - 从单键多值容器访问特定值
- regex - 为什么模式匹配在 Scala 中不起作用?
- windows - 如何使USB驱动器只写并阻止读取访问,只执行并阻止读取访问
- excel - 在Excel中将年份数据列转换为时间序列
- regex - 正则表达式以字符替换结尾