Querydsl:如何选择特定的列

时间:2018-11-01 08:14:05

标签: java spring-data-jpa querydsl

我正在使用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
    }
  },
...
...
]

1 个答案:

答案 0 :(得分:0)

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