我解决了我的问题。为了使它起作用,我做了以下操作:首先,我将依赖关系更改为jackson2
<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.4.3</version></dependency><dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.4.3</version></dependency><dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.4.3</version></dependency>
然后,我用@JsonProperty和@JsonIgnore注释了Book类。这是我更新的书本课
@Entity @Table(name="Book") @Indexed public class Book { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "bookId") @JsonIgnore private Long id; @Column(nullable = false) @Field(index = Index.YES, analyze=Analyze.YES, store=Store.NO) @JsonProperty("title") private String title; @Column(nullable = false, unique = true) @JsonProperty("ISBN") private String ISBN; @Column(nullable = false) @Field(index = Index.YES, analyze=Analyze.YES, store=Store.NO) @JsonProperty("author") private String author; @JsonProperty("publisher") private String publisher; @Column(length = 1000) @JsonProperty("description") private String description; @JsonProperty("publicationYear") private int publicationYear; @JsonProperty("pages") private int pages; @Enumerated(EnumType.STRING) @Column(nullable = false) @JsonIgnore private BookStatus bookStatus; @ManyToMany(mappedBy = "booksWant", cascade = CascadeType.ALL) @JsonIgnore private List<User> user = new ArrayList<User>(0); @oneToMany(mappedBy = "book", cascade = CascadeType.ALL) @JsonIgnore private List<UserBook> bookList = new ArrayList<UserBook>(0); public Book(String title, String ISBN, String author, String publisher, String description, int publicationYear, int pages, BookStatus bookStatus) { this.title = title; this.ISBN = ISBN; this.author = author; this.publisher = publisher; this.description = description; this.publicationYear = publicationYear; this.pages = pages; this.bookStatus = bookStatus; } getters and setters}


