htmlからjavaへリスト型のデータを渡したい

前提

springbootとthymeleafを使って、注文システムを作っています。
htmlからControllerへリストを渡したいのですがうまくいきません。
送信ボタンを押すと後述のエラーが返ってきます。

・画面表示までは問題なくできる
・th:fieldをth:valueに変更すると、送信ボタンが機能し、ヘッダー登録ができる。
・orderControllerの宣言文にブレークポイントをはってもエラー画面が返ってくる

以上のことから、postの際のバインドがうまくいっていないのではと考えているのですが、具体的な解決方法がわかりません。

実際はリストをcontrollerに返した後、DBに登録を行うのですが、その部分は未実装です。
とりあえず、ボタンを押して値が返るところまで作成したいと思っています。

お力添えいただけますと幸いです。

発生している問題・エラーメッセージ

java.lang.NoSuchMethodException: com.example.jrOrder.entity.product.<init>()

該当のソースコード

controller

12@Controller 3public class mainController { 4 5 @Autowired 6 private orderService orderService; 7 8 //注文完了 9 @PostMapping("/orderComplete") 10 public String orderController(@ModelAttribute orderForm orderForm, Model model){ 11 12 //ヘッダー登録 13 LocalDateTime ldt = LocalDateTime.now(); 14 15 DateTimeFormatter orderNoFormat = 16 DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); 17 DateTimeFormatter orderDateFormat = 18 DateTimeFormatter.ofPattern("yyyy-MM-dd"); 19 orderForm.setOrderNo(orderNoFormat.format(ldt)); 20 orderForm.setOrderDate(orderDateFormat.format(ldt)); 21 orderForm.setStatas("未承認"); 22 orderForm.setEmail(loginUserGetter.getUsername()); 23 24 orderService.insertOrder(orderForm); 25 26 //明細登録(未実装) 27 28 29 return "complete"; 30 }

form

1@Data 2public class orderForm { 3 private int CategoryCd; 4 private List<category> categoryList; 5 private List<product> productList; 6 private String statas; 7 private String email; 8 9 private String orderDate; 10 private String orderNo; 11}

entity

12@Data 3public class product { 4 5 private final String name; 6 private final String categoryName; 7 private final String quantity; 8 private final String productCode; 9 private final String subCategoryName; 10}

html

1<form th:action="@{/orderComplete}" th:object="${orderForm}" method="post" >2 3<article>4<div class="side">5 <div class="row form-horizontal">6 <div class="col-sm-12">7 <h4 class="clear hidden-sm hidden-xs">商品分類</h4>8 <div class="bs-component">9 <div class="list-group">10 <div th:each="productCategoryS : *{categoryList}">11 <a12 13 th:href="@{/order/product(categoryCd=${productCategoryS.categoryCd})}"14 class="list-group-item list-group-item-warning"15 th:text="${productCategoryS.name}"16 th:name="categoryCd">17 </a>18 19 </div>20 </div>21 </div>22 </div>23 </div>24</div>25 26 27 28<!-- 一覧 -->29<div class="content">30<div class="upbar">31<label>数量 32<input type="number" th:value="1" th:id="order" min="1" max="10" step="1">33</label>34<input type="button" th:id="quantitybutton" th:value="反映">35</div>36 37<br>38 39<div class="pb-3 px-3 flex-grow-1 overflow-hidden" style="height: 100%">40 <!-- 検索結果 -->41 <div class="table-fixed-header">42 <table class="table table-sm table-striped m-0" id="table">43 <col width="10%"/>44 <col width="15%"/>45 <col width="15%"/>46 <col width="50%%"/>47 <thead>48 <tr>49 <th class="productNumber">品番</th>50 <th class="productName">製品名</th>51 <th class="productQuantity">装備数</th>52 <th class="orderQuantity">発注数量</th>53 </tr>54 </thead>55 <tbody>56 57 <tr th:each="productList,stat : *{productList}" >58 <td>59 <label th:text="${productList.productCode}"></label>60 <input type="hidden" th:field="*{productList[__${stat.index}__].productCode}">61 </td>62 <td>63 <label th:text="${productList.name}"></label>64 <input type="hidden" th:field="*{productList[__${stat.index}__].name}">65 </td>66 <td>67 <label th:text="${productList.quantity}"></label>68 <input type="hidden" th:field="*{productList[__${stat.index}__].quantity}">69 </td>70 <td align="center"> 71 <div th:class="buttonContent">72 <button type="button" class="downbutton"></button>73 <input type="text" th:field="*{productList[__${stat.index}__].quantity}" class="inputtext">74 <button type="button" class="upbutton"></button> 75 </div> 76 </td>77 </tr>78 </tbody>79 </table>80 81 <div class="position-sticky top-100 start-0 py-2">82 83 </div>84 </div>85 </div>86 87 88<input th:id="submit" type="submit" th:value="送信">89</form>90

コメントを投稿

0 コメント