如何在春天只返回特定的字段

时间:2017-06-02 05:51:08

标签: java json spring

在下面的代码中,当我使用投影时,它返回Group的整个对象,但我只想获得roleNameGroup 我怎么能这样做?

投影: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... }

1 个答案:

答案 0 :(得分:1)

首先我尝试@RestResource(exported = false)它没有用,但后来我尝试了  @JsonIgnore它最终有效:'D