[英]Querydsl: How to select specific column
I am using spring data jpa for creating services. 我正在使用spring data jpa创建服务。 Using
Querydsl
I am fetching records from multiple tables. 我使用
Querydsl
从多个表中获取记录。 I used mapping in model classes. 我在模型类中使用了映射。
RoomDepartmentMapping
model class is mapped with department
, and room
. RoomDepartmentMapping
模型类与department
和room
映射。 and room
is mapped with building
. 和
room
映射building
。
I want to select only building name
from building
. 我只想从
building
选择building name
。
Can any one tell me How I can do? 谁能告诉我该怎么办?
QueryDSL 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);
Result 结果
[
{
"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字符串中显示的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.