![](/img/trans.png)
[英]How to retrieve only specific field of a document with Spring Data Mongo DB?
[英]How to return only specific field in spring
在下面的代碼中,當我使用投影時,它返回了Group的整個對象,但是我只想獲取Group
類的roleName
怎么辦?
投影:UserWithProfile
@Projection(name="UserWithProfile",types=User.class)
public interface UserWithProfile extends UserGetters {
UserPhoto getProfilePhoto();
}
用戶提示
public interface UserGetters{
Long getId();
String getName();
String getLogonEmail();
boolean isEmailVerified();
Group getGroup();
}
用戶類
@Entity
public class User implements Serializable, UserGetters {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER, targetEntity = Property.class)
private Set<Property> favouriteProperty;
@OneToOne
private AcceptanceLetter acceptanceLetter;
@Column(unique=true)
private String logonEmail;
private String name;
@JsonProperty(access = Access.WRITE_ONLY)
@Column(updatable=false)
private String password;
private boolean emailVerified;
@ManyToOne
private Group group;
@OneToOne
private Business business;
private String address;
private String postcode;
private String phoneNo;
private String passportNo;
@Column(length=1000)
private String description;
@JsonIgnore
private float meanRating;
@OneToOne(mappedBy="user",targetEntity=UserPhoto.class)
private UserPhoto profilePhoto;
@ManyToOne
private Country country;
Getter and setters... }
首先我嘗試了@RestResource(exported = false)
它沒有用,但是后來我嘗試了@JsonIgnore
它終於可以了:'D
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.