I'm trying to get the data from MSSQL database using below logic. 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.
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:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.