我有2个班级,一个用于用户详细信息,另一个用于用户健身 我想要的是使用 FitnessRecordRepository.findAll()从FitnessRecord类的最终json对象中排除 name 字段。 这是我现在的json输出。
{
"fitness_id": 1,
"date_of_performance": "2018-04-06",
"user": {
"user_id": 1,
"name": "Hilal Kaldane",
"email": "hilalkaldane@gmail.com"
}
}
我想要的是
{
"fitness_id": 1,
"date_of_performance": "2018-04-06",
"user": {
"user_id": 1,
"email": "hilalkaldane@gmail.com"
}
}
User.class
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer user_id;
@NotNull
private String name;
@NotNull
@Column(unique = true)
private String email;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "user")
private Set<FitnessRecord> fitness_record = new HashSet<>();
//Getter and Setters are omitted
}
FitnessRecord.class
public class FitnessRecord {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer fitness_id;
public Integer getFitness_id() {
return fitness_id;
}
public void setFitness_id(Integer fitness_id) {
this.fitness_id = fitness_id;
}
@JoinColumn(name="user_id")
@ManyToOne
private User user;
@Temporal(TemporalType.DATE)
private Date date_of_performance;
}
注意: - 我不想在用户类上使用JSON忽略,因为我将使用 名称 字段其他地方,如用户信息检索