【发布时间】:2022-01-14 17:58:39
【问题描述】:
我想使用 @DocumentReference 和基本的 @Field 注释作为两个属性指向相同的属性(在 mongoDB 中),以便轻松操作它。为了实现这一点,我编写了自定义查找,但问题是,SpEL 中的 #self 为 null 我收到一个错误:
org.springframework.expression.spel.SpelEvaluationException: EL1007E: 在 null 上找不到属性或字段“project_id”
代码:
public record ProjectUser(@Id UUID id,
@Field("contact_email") String contactEmail,
@Field("phone") String phone,
@Field("company") String company,
@Field("job_title") String jobTitle,
@Field("note") String note,
@Field("parent_id") UUID parentId,
@Field("user_id") UUID userId,
@Field("project_id") UUID projectId,
@ReadOnlyProperty @DocumentReference(lookup = "{ '_id' : '?#{#self.project_id}' }") Project project,
@Field("project_role_id") UUID roleId,
@Field("project_group_ids") List<UUID> projectGroupIds,
@Field("deleted") Boolean deleted,
@Field("created_date") @CreatedDate OffsetDateTime createdDate,
@Field("updated_date") @LastModifiedDate OffsetDateTime updatedDate) {
}
有没有办法同时使用 @ReadOnlyProperty @DocumentReference(...) Project project 和 @Field("project_id") UUID projectId ?非常感谢!!!
【问题讨论】:
标签: java spring spring-boot spring-data spring-data-mongodb