2016-05-28 4 views
2

私はSpring Bootで新しく、Thymeleafに問題があります。 For Eachサイクルの下でHTMLフォームを使用したいが、例外を受け取る。ThymeleafのFor-Eachサイクルの下にフォームがある場合

これは私のコードです:

  <tr th:each="item : ${users}"> 
      <td th:text="${item.getFirstName()}">First Name</td> 
      <td th:text="${item.getLastName()}">Last Name</td> 
      <td th:text="${item.getEmailAddress()}">Email Address</td> 
      <td th:text="${item.getDateOfBirth()}">Date of Birth</td> 
      <!--<td><a th:href="${'/user/edit/' + user.id}">Edit</a></td> --> 
      <td>Edit</td> 
      <td> 
       <form th:object="${item}" th:action="@{/delete}" method="post"> 
        <input type="hidden" th:field="*{firstName}"/> 
        <input type="hidden" th:field="*{lastName}"/> 
        <input type="hidden" th:field="*{emailAddress}"/> 
        <input type="hidden" th:field="*{dateOfBirth}"/> 
        <input type="submit" value="Delete"/> 
       </form> 
      </td> 
     </tr> 

そして、これは私が受け取る例外です:

[THYMELEAF][http-nio-8080-exec-1] Exception processing template "users": Error during execution of processor 'org.thymeleaf.spring4.processor.attr.SpringInputGeneralFieldAttrProcessor' (users:31) 

あなたは私が間違って何をやっている私に言うことはできますか?

ありがとうございます!

答えて

-1

私は春のブートアプリケーションのビューエンジンとしてthymeleafを使用しています。下のサンプルコードは、あなたがそれについていくつかのアイデアを得るのを助けるかもしれません。

Userモデル

@Entity 
public class User { 

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    @Column(name="id", nullable = false) 
    private Long id; 

    @Column(name="user_name") 
    private String userName; 


    @Email(message="Email not valid") 
    @Column(name="email",nullable=false) 
    private String email; 

    public Long getId() { 
     return id; 
    } 

    public void setId(Long id) { 
     this.id = id; 
    } 

    public String getUserName() { 
     return userName; 
    } 

    public void setUserName(String userName) { 
     this.userName = userName; 
    } 

} 

ユーザコントローラ

model.addAttribute("users", userService.getAllusers()); 

ユーザービュー

<tr th:each="user : ${users}"> 
    <td th:text="${user.id}"></td> 
    <td th:text="${user.email}"></td> 
    <td th:text="${user.userName}"></td> 
</tr> 
+0

[OK]を、ありがとうございました。私は自分の問題を各ユーザアカウントにidを追加して解決し、POSTクエリで完全なオブジェクトを渡す必要はありませんでした。 –

関連する問題