我正在构建一个类似于以下内容的api:
所以我对etiquetas(“tags”)列表有个问题,我不知道如何让它在我的api中正确地检索不同的值。我在Maven和标签之间建立了一种多对多的关系,比如:
Maven模型:
@Entity
@Table(name="experts")
public class Expert {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String surname;
private String dni;
private String address;
private String mail;
private String phone;
private String created_at;
private String updated_at;
private String linkedln;
private String state;
private String rating;
private String availability;
@ManyToMany(mappedBy="expert", cascade = CascadeType.MERGE,fetch = FetchType.LAZY)
@JsonIgnore
private List<Tag> tags = new ArrayList<>();
public Expert() {
}
public Expert(String name, String surname, String dni, String address, String mail, String phone, String created_at, String updated_at, String linkedln, String state, String rating, List<Tag> tags, String availability) {
this.name = name;
this.surname = surname;
this.dni = dni;
this.address = address;
this.mail = mail;
this.phone = phone;
this.created_at = created_at;
this.updated_at = updated_at;
this.linkedln = linkedln;
this.state = state;
this.rating = rating;
this.tags = tags;
this.availability = availability;
}
my tags model:
@Entity
@Table(name="tags")
public class Tag {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
@ManyToMany(cascade = CascadeType.MERGE)
@JoinTable(
name = "experts_tags",
joinColumns = {@JoinColumn(name="tag_id", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name="expert_id", referencedColumnName = "id")}
)
private List<Expert> expert = new ArrayList<>();
public Tag() {
} //getters and setters
我的expertdao以这种方式在数据库中发布值:
@Override
public Expert postExpert(Expert expert) {
this.manager.persist(expert);
return expert;
}
当我尝试使用postman时,我看到expert已成功发布,但它检索所有值,除了标记one:
当我在heroku中看到我的api时,我看到它发布了ok,但我没有标签字段:
{“id”:174,“name”:“paco”,“姓氏”:“l”ópez,“dni”:“293912393d”,“地址”:“calle obispo 15,madrid”,“邮件”:joaquin@muñoz.com“,”phone“:”6722292394“,”created\u at“:”15/04/2021“,”updated\u at“:”16/05/2021“,”linkedln“:”https://www.linkedin.com/in/sara-b-54b93543/“,”state“:”por validar“,”rating“:”55“,”availability“:”mañ阿纳斯“}]
我要让这个区域出现!我该怎么做???非常感谢您的帮助!提前谢谢。
1条答案
按热度按时间wswtfjt71#
我不是json和java结合的最佳Maven,但是注解
@JsonIgnore
在球场上private List<Tag> tags = new ArrayList<>()
对我来说很可疑。我这边的一个快速测试表明,这样一个带注解的字段的值并没有写入json文件。