コントローラーからこのようなBinderPlaceOrderオブジェクトを送信しています
model.addAttribute("addNewBinderPlaceOrder", new BinderPlaceOrder());
私のThymeleafページは、
<form class="addBinderPlaceOrderForm" role="form" action="#" th:action="@{/binderPlaceOrder/new-binderPlaceOrder}" th:object="${addNewBinderPlaceOrder}" method="post">
<div class="form-group">
<label>Book</label>
<select class="form-control" th:field="*{binderOrderItemDetails.book}">
<option th:if="${book} == null" value=" " >Select Book</option>
<option th:each="book : ${allBook}"
th:value="${book.id}"
th:text="${book.name}">
</option>
</select>
</div>
<form>
これがコントローラーです、
@Controller
@RequestMapping("/binderPlaceOrder")
public class BinderPlaceOrderController{
@Autowired
BinderPlaceOrderService binderPlaceOrderService;
@Autowired
BookService bookService;
@RequestMapping(value="/new-binderPlaceOrder", method = RequestMethod.GET)
public String newBinderPlaceOrder(Model model){
model.addAttribute("addNewBinderPlaceOrder", new BinderPlaceOrder());
model.addAttribute("allBook", bookService.getAllBooks();
model.addAttribute("addNewBinderOrderItemDetails", new BinderOrderItemDetails());
return "user/binderPlaceOrder/new";
}
}
実行時に以下のエラーが発生します
org.springframework.beans.NotReadablePropertyException:Beanクラス[PublisherInventory.model.user.BinderPlaceOrder]の無効なプロパティ 'binderOrderItemDetails.book':Beanプロパティ 'binderOrderItemDetails.book'が読み取れないか、無効なゲッターメソッドがあります。ゲッターはセッターのパラメータータイプと一致しますか?
以下はクラスです。
すべてのクラスには、他のプロパティとともに独自のIdプロパティがあることに注意してください。読みやすくするために、これらは省略されています。
これがBinderPlaceOrderクラスです。
@Entity
public class BinderPlaceOrder implements Comparator<BinderPlaceOrder> {
@OneToMany(mappedBy = "binderPlaceOrder", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<BinderOrderItemDetails> binderOrderItemDetails;
public List<BinderOrderItemDetails> getBinderOrderItemDetails() {
return binderOrderItemDetails;
}
public void setBinderOrderItemDetails(List<BinderOrderItemDetails> binderOrderItemDetails) {
this.binderOrderItemDetails = binderOrderItemDetails;
}
}
これがBinderOrderItemDetailsクラスです
@Entity
@Indexed
public class BinderOrderItemDetails {
@OneToOne(fetch = FetchType.EAGER,cascade = CascadeType.ALL)
@JoinColumn(name="bookId")
private Book book;
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name="binderPlaceOrderId")
private BinderPlaceOrder binderPlaceOrder;
public Book getBook() { return book; }
public void setBook(Book book) { this.book = book; }
public BinderPlaceOrder getBinderPlaceOrder() { return binderPlaceOrder; }
public void setBinderPlaceOrder(BinderPlaceOrder binderPlaceOrder) {
this.binderPlaceOrder = binderPlaceOrder; }
}
これが本のクラスです
@Entity
@Indexed
public class Book implements Comparator<Book> {
@Column(name = "name")
@NotNull
@NotBlank
private String name;
public String getName() { return name; }
public void setName(String name) { this.name = name;}
}
私が間違っていることや、それをどのように解決できるかを教えてください。
前もって感謝します。
@JBNizetが指摘したように、BinderPlaceOrderには
public List<BinderOrderItemDetails> getBinderOrderItemDetails() {
return binderOrderItemDetails;
}
これはリストなので、
th:field="*{binderOrderItemDetails.book}"
正しくないでしょう、
ただし、最初の要素を挿入するとします。
th:field="${binderOrderItemDetails[0].book}"
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加