質問編集履歴
4
エラーメッセージに機密情報があったため削除した
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,339 +1,128 @@
|
|
1
1
|
##やりたいこと
|
2
|
-
|
3
2
|
SpringBootとThymeleafでWEBアプリを開発しております。
|
4
|
-
|
5
3
|
テーブルの端にチェックボックスを用意し、ボタンを押すとチェックした項目をすべてDBから削除するような処理を作ろうとしています。
|
6
|
-
|
7
4
|
テーブルの表示まではできたのですが、Contorollerに受け渡すことができず質問させていただきました。
|
8
|
-
|
9
5
|
Excelのスクリーンショットですが完成イメージです↓
|
10
|
-
|
11
6
|
※削除ボタンを押すとDBから「tanaka」と「yamada」が削除されるイメージです。
|
12
|
-
|
13
7
|
![イメージ説明](7eb49d629ae89ccc762cf24390f0f922.png)
|
14
8
|
|
15
9
|
|
16
10
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
11
|
##ソースコード
|
22
|
-
|
23
12
|
```Java
|
24
|
-
|
25
13
|
import lombok.Data;
|
26
14
|
|
27
|
-
|
28
|
-
|
29
15
|
@Data
|
30
|
-
|
31
16
|
public class Person {
|
32
|
-
|
33
17
|
private int id;
|
34
|
-
|
35
18
|
private String name;
|
36
|
-
|
37
19
|
private int age;
|
38
|
-
|
39
20
|
private boolean checked;
|
40
21
|
|
41
|
-
|
42
|
-
|
43
22
|
public Person(int id, String name, int age, boolean checked) {
|
44
|
-
|
45
23
|
this.setId(id);
|
46
|
-
|
47
24
|
this.setName(name);
|
48
|
-
|
49
25
|
this.setAge(age);
|
50
|
-
|
51
26
|
this.setChecked(checked);
|
52
|
-
|
53
27
|
}
|
54
|
-
|
55
28
|
}
|
56
|
-
|
57
|
-
|
58
29
|
|
59
30
|
```
|
60
31
|
|
61
|
-
|
62
|
-
|
63
32
|
```Java
|
64
|
-
|
65
33
|
import java.util.List;
|
66
|
-
|
67
34
|
import lombok.Data;
|
68
35
|
|
69
|
-
|
70
|
-
|
71
36
|
@Data
|
72
|
-
|
73
37
|
public class PersonForm {
|
74
|
-
|
75
38
|
private List<Person> personList;
|
76
|
-
|
77
39
|
}
|
78
|
-
|
79
|
-
|
80
40
|
|
81
41
|
```
|
82
42
|
|
83
|
-
|
84
|
-
|
85
43
|
```Java
|
86
|
-
|
87
44
|
//Controller
|
88
|
-
|
89
45
|
@RequestMapping("/editPersonList")
|
90
|
-
|
91
46
|
public String editPersonList(Model model) {
|
92
|
-
|
93
47
|
Person person1 = new Person(1, "tanaka", 30, false);
|
94
|
-
|
95
48
|
Person person2 = new Person(2, "tanaka", 40, false);
|
96
|
-
|
97
49
|
Person person3 = new Person(3, "tanaka", 50, false);
|
98
50
|
|
99
|
-
|
100
|
-
|
101
51
|
List<Person> personList = new ArrayList<Person>();
|
102
|
-
|
103
52
|
personList.add(person1);
|
104
|
-
|
105
53
|
personList.add(person2);
|
106
|
-
|
107
54
|
personList.add(person3);
|
108
55
|
|
109
|
-
|
110
|
-
|
111
56
|
PersonForm personForm = new PersonForm();
|
112
|
-
|
113
57
|
personForm.setPersonList(personList);
|
114
|
-
|
115
|
-
|
116
58
|
|
117
59
|
model.addAttribute("personForm", personForm);
|
118
60
|
|
119
|
-
|
120
|
-
|
121
61
|
return "/editPersonList";
|
122
|
-
|
123
62
|
}
|
124
63
|
|
125
|
-
|
126
|
-
|
127
64
|
@PostMapping("/updatePersonList")
|
128
|
-
|
129
65
|
public String updatePersonList(@ModelAttribute PersonForm personForm) {
|
130
|
-
|
131
66
|
// DB更新処理
|
132
|
-
|
133
67
|
System.out.println(personForm);
|
134
68
|
|
135
|
-
|
136
|
-
|
137
69
|
return "redirect:/top_page";
|
138
|
-
|
139
70
|
}
|
140
|
-
|
141
71
|
```
|
142
72
|
|
143
|
-
|
144
|
-
|
145
73
|
```html
|
146
|
-
|
147
74
|
<!DOCTYPE html>
|
148
|
-
|
149
75
|
<html lang="jp">
|
150
|
-
|
151
76
|
<html xmlns:th="http://www.thymeleaf.org">
|
152
77
|
|
153
|
-
|
154
|
-
|
155
78
|
<head>
|
156
|
-
|
157
79
|
<title>ユーザー編集</title>
|
158
|
-
|
159
80
|
<meta charset="UTF-8">
|
160
|
-
|
161
81
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
162
|
-
|
163
82
|
<link rel="stylesheet" type="text/css" href="/css/new_common.css">
|
164
|
-
|
165
83
|
</head>
|
166
84
|
|
167
|
-
|
168
|
-
|
169
85
|
<body>
|
170
|
-
|
171
86
|
<div th:replace="header_design :: header_design"></div>
|
172
|
-
|
173
87
|
<div style="margin-top: 100px;">テスト用画面</div>
|
174
|
-
|
175
88
|
<p>ユーザ一覧</p>
|
176
|
-
|
177
89
|
<form th:action="@{/updatePersonList}" th:method="post" th:object="${personForm}">
|
178
|
-
|
179
90
|
<table>
|
180
|
-
|
181
91
|
<thead>
|
182
|
-
|
183
92
|
<tr>
|
184
|
-
|
185
93
|
<td>ID</td>
|
186
|
-
|
187
94
|
<td>名前</td>
|
188
|
-
|
189
95
|
<td>年齢</td>
|
190
|
-
|
191
96
|
<td>削除フラグ</td>
|
192
|
-
|
193
97
|
</tr>
|
194
|
-
|
195
98
|
</thead>
|
196
|
-
|
197
99
|
<tbody>
|
198
|
-
|
199
100
|
<th:block th:each="person,stat : *{personList}">
|
200
|
-
|
201
101
|
<tr>
|
202
|
-
|
203
102
|
<td><input type="text" th:field="*{personList[__${stat.index}__].id}"></td>
|
204
|
-
|
205
103
|
<td><input type="text" th:field="*{personList[__${stat.index}__].name}"></td>
|
206
|
-
|
207
104
|
<td><input type="text" th:field="*{personList[__${stat.index}__].age}"></td>
|
208
|
-
|
209
105
|
<td><input type="checkbox" th:field="*{personList[__${stat.index}__].checked}"></td>
|
210
|
-
|
211
106
|
<!-- ↓試したけどエラーが発生した-->
|
212
|
-
|
213
107
|
<!-- <td><input type="text" th:field="${person.id}"></td>
|
214
|
-
|
215
108
|
<td><input type="text" th:field="${person.name}"></td>
|
216
|
-
|
217
109
|
<td><input type="text" th:field="${person.age}"></td>
|
218
|
-
|
219
110
|
<td><input type="checkbox" th:field="${person.checked}"></td> -->
|
220
|
-
|
221
111
|
</tr>
|
222
|
-
|
223
112
|
</th:block>
|
224
|
-
|
225
113
|
</tbody>
|
226
|
-
|
227
114
|
</table>
|
228
|
-
|
229
115
|
<input type="submit" value="更新">
|
230
|
-
|
231
116
|
</form>
|
232
|
-
|
233
117
|
</body>
|
234
118
|
|
235
|
-
|
236
|
-
|
237
119
|
</html>
|
238
|
-
|
239
120
|
```
|
240
121
|
|
241
|
-
|
242
|
-
|
243
122
|
##エラーメッセージ
|
244
|
-
|
245
|
-
文字数制限のため下の方を削っております。
|
246
|
-
|
247
|
-
```
|
248
|
-
|
249
|
-
This application has no explicit mapping for /error, so you are seeing this as a fallback.
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
Fri Mar 06 14:45:23 JST 2020
|
254
|
-
|
255
|
-
There was an unexpected error (type=Internal Server Error, status=500).
|
256
|
-
|
257
|
-
Invalid property 'personList[0]' of bean class [com.example.mistuto.model.PersonForm]: Illegal attempt to get property 'personList' threw exception; nested exception is org.springframework.beans.NullValueInNestedPathException: Invalid property 'personList' of bean class [com.example.mistuto.model.PersonForm]: Could not instantiate property type [com.example.mistuto.model.Person] to auto-grow nested property path; nested exception is java.lang.NoSuchMethodException: com.example.mistuto.model.Person.<init>()
|
258
|
-
|
259
|
-
org.springframework.beans.InvalidPropertyException: Invalid property 'personList[0]' of bean class [com.example.mistuto.model.PersonForm]: Illegal attempt to get property 'personList' threw exception; nested exception is org.springframework.beans.NullValueInNestedPathException: Invalid property 'personList' of bean class [com.example.mistuto.model.PersonForm]: Could not instantiate property type [com.example.mistuto.model.Person] to auto-grow nested property path; nested exception is java.lang.NoSuchMethodException: com.example.mistuto.model.Person.<init>()
|
260
|
-
|
261
|
-
at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:707)
|
262
|
-
|
263
|
-
at org.springframework.beans.AbstractNestablePropertyAccessor.getNestedPropertyAccessor(AbstractNestablePropertyAccessor.java:839)
|
264
|
-
|
265
|
-
at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyAccessorForPropertyPath(AbstractNestablePropertyAccessor.java:816)
|
266
|
-
|
267
|
-
at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:256)
|
268
|
-
|
269
|
-
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:97)
|
270
|
-
|
271
|
-
at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:848)
|
272
|
-
|
273
|
-
at org.springframework.validation.DataBinder.doBind(DataBinder.java:744)
|
274
|
-
|
275
|
-
at org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:197)
|
276
|
-
|
277
|
-
at org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:107)
|
278
|
-
|
279
|
-
at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.bindRequestParameters(ServletModelAttributeMethodProcessor.java:158)
|
280
|
-
|
281
|
-
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:160)
|
282
|
-
|
283
|
-
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121)
|
284
|
-
|
285
|
-
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:167)
|
286
|
-
|
287
|
-
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134)
|
288
|
-
|
289
|
-
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)
|
290
|
-
|
291
|
-
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:888)
|
292
|
-
|
293
|
-
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)
|
294
|
-
|
295
|
-
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
|
296
|
-
|
297
|
-
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
|
298
|
-
|
299
|
-
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
|
300
|
-
|
301
|
-
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
|
302
|
-
|
303
|
-
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
|
304
|
-
|
305
|
-
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
|
306
|
-
|
307
|
-
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
|
308
|
-
|
309
|
-
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
|
310
|
-
|
311
|
-
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
|
312
|
-
|
313
|
-
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
|
314
|
-
|
315
|
-
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
|
316
|
-
|
317
|
-
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
|
318
|
-
|
319
|
-
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
|
320
|
-
|
321
|
-
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)
|
322
|
-
|
323
|
-
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:126)
|
324
|
-
|
325
|
-
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90)
|
326
|
-
|
327
|
-
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
|
328
|
-
|
329
|
-
```
|
330
|
-
|
331
|
-
|
123
|
+
諸事情により削除させていただきました
|
332
124
|
|
333
125
|
参考にさせて頂いたサイト
|
334
|
-
|
335
126
|
https://area-b.com/blog/2015/02/04/2009/
|
336
127
|
|
337
|
-
|
338
|
-
|
339
128
|
よろしくお願いいたします。
|
3
文言の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -208,7 +208,7 @@
|
|
208
208
|
|
209
209
|
<td><input type="checkbox" th:field="*{personList[__${stat.index}__].checked}"></td>
|
210
210
|
|
211
|
-
<!-- ↓エラーが発生
|
211
|
+
<!-- ↓試したけどエラーが発生した-->
|
212
212
|
|
213
213
|
<!-- <td><input type="text" th:field="${person.id}"></td>
|
214
214
|
|
2
タイトルの修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
テーブルに表示したデータを編集し、全行一括で更新したい
|
test
CHANGED
File without changes
|
1
タイトルの修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
フォームをリスト状にして
|
1
|
+
フォームをリスト状にしてテーブルに表示し、編集したい
|
test
CHANGED
File without changes
|