我正在使用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
}
},
...
...
]
QueryDsl似乎没有提供自定义要显示的字段的方法,选择是使用jackson的@JsonProperty(serialized = false),它将隐藏您不希望在json字符串中显示的属性。