在下面的代码中,当我使用投影时,它返回 Group 的整个对象,但我只想获取类 Group
的 roleName
我该怎么做?
投影:UserWithProfile
@Projection(name="UserWithProfile",types=User.class)
public interface UserWithProfile extends UserGetters {
UserPhoto getProfilePhoto();
}
UserGetters
public interface UserGetters{
Long getId();
String getName();
String getLogonEmail();
boolean isEmailVerified();
Group getGroup();
}
用户.class
@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
关于java - 如何在 Spring 中仅返回特定字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44321698/