簡體   English   中英

如何在春季只返回特定領域

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM