0
在下面的代码中,当我使用投影时,它返回了我的整个对象组,但我只想得到roleName
类Group
我该怎么做?如何仅在春季返回特定字段
投影: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();
}
User.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... }
使用杰克逊的@JsonIgnore的确是要走的路。查看文档; https://docs.spring.io/spring-data/rest/docs/current/reference/html/#projections-excerpts.projections.hidden-data –