Querydsl:如何选择特定列

问题描述 投票:0回答:1

我正在使用spring data jpa来创建服务。使用Querydsl我从多个表中获取记录。我在模型类中使用了映射。 RoomDepartmentMapping模型类与departmentroom映射。和roombuilding映射。

我想从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
    }
  },
...
...
]
java spring-data-jpa querydsl
1个回答
0
投票

QueryDsl似乎没有提供自定义要显示的字段的方法,选择是使用jackson的@JsonProperty(serialized = false),它将隐藏您不希望在json字符串中显示的属性。

© www.soinside.com 2019 - 2024. All rights reserved.