現在Spring boot + Thymeleafで開発をしています。
初心者のため、詳しくご教授頂けると幸いです。
実現したいこと
一覧画面で入力された値をControllerで取得したい。
発生している問題・エラーメッセージ
画面の値を参照しようとするとNullPointerExceptionが発生する
Java
1@Entity 2@Data 3public class TableColumn { 4 @Id 5 public String no; 6 7 public String table_name; 8 9 public String komoku_name; 10 11 public String type; 12 13 public String length; 14 15 public String checkbox 16 17 public String jyoken; 18 19 public String atai; 20}
Java
1public class TableColumnDto implements Serializable{ 2@Data 3 @Id 4 public String no; 5 6 public String table_name; 7 8 public String komoku_name; 9 10 public String type; 11 12 public String length; 13 14 public String checkbox; 15 16 public String jyoken; 17 18 public String atai; 19}
Java
1@Data 2public class ColumnListParam implements Serializable { 3 @Valid 4 public List<TableColumnDto> tableColumnList; 5} 6
Java
1@Controller 2public class TableColumnController { 3 @Autowired 4 TableService tableService; 5 6 @RequestMapping(value = "/excel",method = RequestMethod.GET) 7 public ModelAndView downloadXlsx(@ModelAttribute("columnListParam") ColumnListParam columnList, ModelAndView mav) { 8 9 /*ここでcolumnList.getTableColumnList().get(0).getJyoken());やcolumnList.getTableColumnList().get(0).getAtai()の 10 値を取得したいが、NullPointerExceptionが発生する 11 */ 12 13 List<Syain> syain = tableService.findSyain(); 14 return new ModelAndView(new DownloadXlsxView(), "syain", syain); 15 } 16 17} 18
どこかおかしい部分はあるでしょうか?
ご教授よろしくお願いします。
引用テキスト
回答ありがとうございました。
ご指摘頂いた通り、name属性を追記して以下のようなHTMLに修正しましたが、
エラーは変わりませんでした。
詳細なエラーも追記します。
HTML
1<!DOCTYPE html> 2<html xmlns:th="http://www.thymeleaf.org"> 3<head> 4 <meta charset="UTF-8"> 5 <link th:href="@{/css/style.css}" rel="stylesheet"> 6 <script th:src="@{/js/common.js}"></script> 7 <title>EUCtools</title> 8<title>テーブルダウンロード</title> 9</head> 10<body> 11<form th:action="@{/tableDownload}" th:object="${columnListParam}" method="post"> 12<div id="Layer0" class="titleArea"> </div> 13<div id="Layer1" class="dateArea"><span th:text="${today}"></span></div> 14<div id="Layer2" class="userArea" rendered="#{gamenKyotu.syainName!=null}">ログインユーザー:<span th:text="${loginname}"></span></div> 15<div id="Layer3" class="endBtnArea"><a onclick="return closeWindow();"><img src="../../images/btn_end.gif" alt="終了" class="imgBtn"></a></div> 16<div id="Layer4" class="screenNaviArea"><span value="#{gamenKyotu.navigationBar}">テーブルダウンロード画面</span></div> 17<div id="Layer5" class="screenTitleArea1"></div> 18<div id="Layer6" class="screenTitleText"></div> 19<div id="Layer7"><span>X99-99-99G</span></div> 20<div id="Layer8" class="bodyAreaNew"> 21<table width="933" cellpadding="0" cellspacing="0"> 22 23 <tr> 24 <td> 25 <div style="width:820px"> 26 <table cellpadding="0" cellspacing="0"> 27 <col style="width:50px"/> 28 <col style="width:200px"/> 29 <col style="width:100px"/> 30 <col style="width:100px"/> 31 <col style="width:50px"/> 32 <col style="width:100px"/> 33 <col style="width:200px"/> 34 <tr> 35 <th class="list">No.</th> 36 <th class="list">項目名</th> 37 <th class="list">データ型</th> 38 <th class="list">長さ</th> 39 <th class="list">選択</th> 40 <th class="list">条件</th> 41 <th class="list">フィルター</th> 42 </tr> 43 </table> 44 </div> 45 </td> 46 </tr> 47 <tr> 48 <td> 49 <div style="height:351px; overflow-y:scroll;width:820px"> 50 <table class="line" cellpadding="0" cellspacing="0" width="800px"> 51 <col style="width:50px"/> 52 <col style="width:200px"/> 53 <col style="width:100px"/> 54 <col style="width:100px"/> 55 <col style="width:50px"/> 56 <col style="width:100px"/> 57 <col style="width:200px"/> 58 <tr th:each="tableColumn, st : *{tableColumnList}"> 59 <td class="left"><span th:text="${tableColumn.no}"></span> 60 <input type="hidden" th:field="*{tableColumnList[__${st.index}__].no}" th:name="${st.count}"></td> 61 <td class="left"><span th:text="${tableColumn.komoku_name}"></span> 62 <input type="hidden" th:field="*{tableColumnList[__${st.index}__].komoku_name}" th:name="${st.count}"></td> 63 <td class="left"><span th:text="${tableColumn.type}"></span> 64 <input type="hidden" th:field="*{tableColumnList[__${st.index}__].type}" th:name="${st.count}"></td> 65 <td class="left"><span th:text="${tableColumn.length}"></span> 66 <input type="hidden" th:field="*{tableColumnList[__${st.index}__].length}" th:name="${st.count}"></td> 67 <td class="left"><input type="checkbox" name="checkbox" th:value="*{tableColumnList[__${st.index}__].checkbox}" th:checked="*{tableColumnList[__${st.index}__].checkbox}"></input></td> 68 <td class="left"> 69 <select th:value="*{tableColumnList[__${st.index}__].jyoken}" th:name="${st.count}"> 70 <option value="0"></option> 71 <option value="1"> = </option> 72 <option value="2"> >= </option> 73 <option value="3"> <= </option> 74 </select> 75 </td> 76 <td class="left"><input type="text" th:name="${st.count}" size="20" th:field="*{tableColumnList[__${st.index}__].atai}" class="inputn"></input></td> 77 </tr> 78 </table> 79 </div> 80 </td> 81 </tr> 82</table> 83</div> 84<div id="Layer11" class="btnArea"> 85<table> 86<tr> 87<td width="10" class="nonp"> </td> 88<td width="110" class="nonp"><a th:href="@{/excel}"><img src="../../images/btn_download.gif" alt="ダウンロード" class="imgBtn"/></a></td><td width="10" class="nonp"> </td> 89<td width="110" class="nonp"> </td><td width="10" class="nonp"> </td> 90<td width="110" class="nonp"> </td><td width="10" class="nonp"> </td> 91<td width="110" class="nonp"> </td><td width="10" class="nonp"> </td> 92<td width="110" class="nonp"> </td><td width="10" class="nonp"> </td> 93<td width="110" class="nonp"> </td><td width="10" class="nonp"> </td> 94<td width="110" class="nonp"> </td><td width="10" class="nonp"> </td> 95<td width="110" class="nonp"> </td><td width="10" class="nonp"> </td> 96<td width="110" class="nonp"><a th:href="@{/menu}"><img src="../../images/btn_modoru.gif" alt="戻る" class="imgBtn"/></a></td><td width="10" class="nonp"> </td> 97<td width="10" class="nonp"> </td> 98</tr> 99</table> 100</div> 101</form> 102</body> 103</html>
発生している問題・エラーメッセージ
[dispatcherServlet] [0;39m [2m:[0;39m Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause java.lang.NullPointerException: null at com.builders.euctools.controller.TableColumnController.downloadXlsx(TableColumnController.java:36) ~[classes/:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
回答2件
あなたの回答
tips
プレビュー