[英]Options to return a custom complex object from a spring data jpa
I'm trying to get the data from MSSQL database using below logic.我正在尝试使用以下逻辑从 MSSQL 数据库中获取数据。 Couldnt identify the option to prepare a single query (SQL or JPQL) to get the repository reponse as MyTestSTO.Can someone suggest me the options available to acheive this.无法确定准备单个查询(SQL 或 JPQL)以使存储库响应为 MyTestSTO 的选项。有人可以向我建议可用于实现此目的的选项。
Expected object Format :预期对象格式:
{
"id": "1",
"name": "Test",
"CabInfo": {
"CabStatus": 0,
"CabStatusStr": "Active",
"CabFunctionalArea": {
"FunctionalAreaId": 3
},
"CabApplication": {
"ApplicationId": 333,
"ApplicationAcronym": "OBM Router"
}
}
}
And JPARepository Class is :
public interface FloorPlanRepositoryExt extends JpaRepository<Sites, Long> {
//Other APIs on Sites Table.
Can we use multiple news in below query ?
@Query(value = "select new TestDTo(sp.id,sp.name,sp.cabStatus,sp.cabStatusStr,
sp.functionalArea,sp.applicationId,sp.ApplicationAcronym) from SpacePower sp where sp.roomId=:roomId)
public List<TestDTo> getRoomSpacesCabByRoomId(@Param("roomId")Integer roomId);
}
My custom DTO is below:我的自定义 DTO 如下:
class TestDTo implements serializable{
private String id;
privateString name;
private CabInfo cabInfo
//Setters and getters and Constructor
}
class CabInfo{
private String cabStatus;
private String CabStatusStr;
private CabFunctionalArea cabFunctionalArea;
private CabApplication CabApplication;
//Setters and getters and Constructor
}
在选择查询中您期望TestDTo
但在返回方法中您定义RoomSpacesCabDTO
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.