0

@ModelAttributeユーザーがデータベース (book テーブル) に新しい本を追加したいときに、注釈を使用してユーザー入力をバインドしようとしています。Book クラスには 4 つのプロパティ ( int bookId, String title, Author author, Publisher publisher) があります。ユーザーはタイトルを入力し、ドロップダウン リストから著者と発行者を選択するだけです。フォームが送信されると、タイトルの値だけがコントローラーのモデル オブジェクトに渡され、作成者と発行者は null になります。フォームとリクエスト ハンドラー メソッドを以下に示します。私のフォームまたはおそらく私のコントローラークラスのどこに問題があると誰かが言うことができますか?

addBook.jsp

<form action="addBookExecution" method="post">
<table>
<tr>
    <td>Enter Book's Name:</td>
    <td><input type="text" name="title"/></td>
</tr>
<tr>
    <td>Select Author: </td>
    <td><select name="author">
                <option>****select author****</option>
                <c:forEach var="author" items="${authorList}">
                    <option value="${author}">${author.authorName}</option>
                </c:forEach>
        </select>
    </td>
</tr>
<tr>
    <td>Select Publisher: </td>
    <td><select name="publisher">
                <option>****select publisher****</option>
                <c:forEach var="publisher" items="${publisherList}">
                    <option value="${publisher}">${publisher.publisherName}</option>
                </c:forEach>
        </select>
    </td>
</tr>
<tr>
    <td>Click here to submit the form:</td>
    <td><input type="submit" value="submit"/></td>
</tr>

コントローラ:

@RequestMapping(value = "/addBookExecution", method = RequestMethod.POST)
protected ModelAndView addBookExecution(@ModelAttribute Book book)
        throws ClassNotFoundException, SQLException {
    bookService.addBook(book);
    ModelAndView model = new ModelAndView("adminFunctionsPage");
    model.addObject("Msg","Your request has been processed successfully.");
    return model;

}
4

1 に答える 1