我正在使用spring data jpa创建服务。我使用Querydsl
从多个表中获取记录。我在模型类中使用了映射。 RoomDepartmentMapping
模型类与department
和room
映射。并且room
与building
映射。
我只想从building name
中选择building
。
有人可以告诉我该怎么做吗?
QueryDSL
query.select(Projections.bean(RoomDepartmentMapping.class,roomDepartmentMapping.nRoomAllocationId,roomDepartmentMapping.sStatus,
Projections.bean(Department.class,department.nDeptId,department.sClientDeptId,department.sDeptName).as("department"),
Projections.bean(Room.class,room.nRoomId,room.sFloor,room.sRoomNumber,room.nBuildId,room.nCampusId,room.building).as("room")))
.from(roomDepartmentMapping);
结果
[
{
"nRoomAllocationId": 1,
"sStatus": "A",
"department": {
"nDeptId": 21920,
"sDeptName": "Unassignable Space",
"sClientDeptId": "BBBBBB"
},
"room": {
"nRoomId": 883886,
"nCampusId": 231,
"nBuildId": 9713,
"sFloor": "9",
"sRoomNumber": "914",
"building": {
"nBuildingId": 9713,
"sBuildName": "Bronk Laboratory",
"sClientBuildId": "406",
"nBuildingInstId": 60,
"nTempBuildingId": 2,
"nNoOfFloors": 0
},
"nroomId": 883886
}
},
...
...
]
答案 0 :(得分:0)
QueryDsl似乎没有提供一种自定义要显示的字段的方法, 选择是使用杰克逊的@JsonProperty(serialized = false),它将隐藏您不想在json字符串中显示的属性。