質問編集履歴
6
テキストの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,16 +4,34 @@
|
|
4
4
|
|
5
5
|
### 問題
|
6
6
|
|
7
|
-
Entityクラスのフィールド変数の中で、@NotNull private Date register;のエラーメッセージ
|
7
|
+
Entityクラスのフィールド変数の中で、@NotNull private Date register;のエラーメッセージが意図しないメッセージが出ます。
|
8
|
+
|
9
|
+
解決策として、@DateTimeFormat(pattern="yyyy/MM/dd")も付与したところ意図したエラーメッセージが出たので解決したと思いきや、入力して登録した時にエラーが出ます。
|
10
|
+
|
11
|
+
入力フォームの値はyyyy/MM/ddです。
|
12
|
+
|
13
|
+
@DateTimeFormat(pattern="yyyy/MM/dd")を付与してない時は登録が○
|
14
|
+
|
15
|
+
@DateTimeFormat(pattern="yyyy/MM/dd")を付与した場合登録が×
|
16
|
+
|
17
|
+
@DateTimeFormat(pattern="yyyy/MM/dd")を付与してない時の空入力時は意図しないエラーメッセージ
|
18
|
+
|
19
|
+
@DateTimeFormat(pattern="yyyy/MM/dd")を付与している時の空入力時は意図したエラーメッセージ
|
20
|
+
|
21
|
+
という状況です。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
### @DateTimeFormat(pattern="yyyy/MM/dd")を付与して登録した時のエラー
|
26
|
+
|
27
|
+
Failed to convert property value of type java.lang.String to required type java.sql.Date for property register; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.validation.constraints.NotNull @org.springframework.format.annotation.DateTimeFormat java.sql.Date] for value 2019-09-01; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2019-09-01]
|
28
|
+
|
29
|
+
### @DateTimeFormat(pattern="yyyy/MM/dd")を付与しないで空入力登録した時のエラー
|
8
30
|
|
9
31
|
Failed to convert property value of type java.lang.String to required type java.sql.Date for property register; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.validation.constraints.NotNull java.sql.Date] for value '; nested exception is java.lang.IllegalArgumentException
|
10
32
|
|
11
33
|
|
12
34
|
|
13
|
-
### 原因の予想
|
14
|
-
|
15
|
-
Date型に@NotNullを付与してますが、そもそもアノテーションが対応していないのかもしれません。。。
|
16
|
-
|
17
35
|
|
18
36
|
|
19
37
|
解決方法をご教授ください・・・。
|
5
テキストの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -364,7 +364,7 @@
|
|
364
364
|
|
365
365
|
<div class="form-group"
|
366
366
|
|
367
|
-
th:classappend="${#fields.hasErrors('regist')}?'has-error'">
|
367
|
+
th:classappend="${#fields.hasErrors('register')}?'has-error'">
|
368
368
|
|
369
369
|
<label class="form-control-label">登録日</label>
|
370
370
|
|
4
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -306,7 +306,7 @@
|
|
306
306
|
|
307
307
|
class="text-danger" th:if="${#fields.hasErrors('title')}"
|
308
308
|
|
309
|
-
th:errors="*{title}">
|
309
|
+
th:errors="*{title}">error</span>
|
310
310
|
|
311
311
|
</div>
|
312
312
|
|
@@ -320,7 +320,7 @@
|
|
320
320
|
|
321
321
|
<input class="form-control" type="text" name="person" /> <span class="text-danger"
|
322
322
|
|
323
|
-
th:if="${#fields.hasErrors('person')}" th:errors="*{person}">
|
323
|
+
th:if="${#fields.hasErrors('person')}" th:errors="*{person}">error</span>
|
324
324
|
|
325
325
|
</div>
|
326
326
|
|
@@ -334,7 +334,7 @@
|
|
334
334
|
|
335
335
|
class="text-danger" th:if="${#fields.hasErrors('page')}"
|
336
336
|
|
337
|
-
th:errors="*{page}">
|
337
|
+
th:errors="*{page}">error</span>
|
338
338
|
|
339
339
|
</div>
|
340
340
|
|
@@ -358,7 +358,7 @@
|
|
358
358
|
|
359
359
|
th:if="${#fields.hasErrors('selectCategory')}"
|
360
360
|
|
361
|
-
th:errors="*{selectCategory}">
|
361
|
+
th:errors="*{selectCategory}">error</span>
|
362
362
|
|
363
363
|
</div>
|
364
364
|
|
@@ -368,11 +368,11 @@
|
|
368
368
|
|
369
369
|
<label class="form-control-label">登録日</label>
|
370
370
|
|
371
|
-
<input class="form-control" type="date" name="regist" /> <span
|
371
|
+
<input class="form-control" type="date" name="register" /> <span
|
372
|
-
|
372
|
+
|
373
|
-
class="text-danger" th:if="${#fields.hasErrors('regist')}"
|
373
|
+
class="text-danger" th:if="${#fields.hasErrors('register')}"
|
374
|
-
|
374
|
+
|
375
|
-
th:errors="*{regist}">
|
375
|
+
th:errors="*{register}">error</span>
|
376
376
|
|
377
377
|
</div>
|
378
378
|
|
3
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,9 +4,9 @@
|
|
4
4
|
|
5
5
|
### 問題
|
6
6
|
|
7
|
-
Entityクラスのフィールド変数の中で、@NotNull private Date regist;のエラーメッセージの出力がデフォルト表示になってしまっています。
|
8
|
-
|
9
|
-
Failed to convert property value of type java.lang.String to required type java.sql.Date for property regist; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.validation.constraints.NotNull java.sql.Date] for value '; nested exception is java.lang.IllegalArgumentException
|
7
|
+
Entityクラスのフィールド変数の中で、@NotNull private Date register;のエラーメッセージの出力がデフォルト表示になってしまっています。
|
8
|
+
|
9
|
+
Failed to convert property value of type java.lang.String to required type java.sql.Date for property register; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.validation.constraints.NotNull java.sql.Date] for value '; nested exception is java.lang.IllegalArgumentException
|
10
10
|
|
11
11
|
|
12
12
|
|
@@ -212,7 +212,7 @@
|
|
212
212
|
|
213
213
|
@NotNull
|
214
214
|
|
215
|
-
private Date regist;
|
215
|
+
private Date register;
|
216
216
|
|
217
217
|
|
218
218
|
|
@@ -258,9 +258,9 @@
|
|
258
258
|
|
259
259
|
#登録日
|
260
260
|
|
261
|
-
book.regist=登録日
|
261
|
+
book.register=登録日
|
262
|
-
|
262
|
+
|
263
|
-
NotNull.book.regist={0}を記入してください
|
263
|
+
NotNull.book.register={0}を記入してください
|
264
264
|
|
265
265
|
```
|
266
266
|
|
2
テキストの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,28 +1,18 @@
|
|
1
1
|
### やりたい事
|
2
2
|
|
3
|
-
現在入力フォームを空で入力した際にmessage.propertiesに記述したエラーメッセージを出力するプログラムを書いています。
|
4
|
-
|
5
|
-
###
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
An error happened during template parsing (template: "class path resource [templates/books/new.html]")
|
14
|
-
|
15
|
-
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/books/new.html]")
|
16
|
-
|
17
|
-
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241)
|
18
|
-
|
19
|
-
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100)
|
20
|
-
|
21
|
-
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:666)
|
3
|
+
現在入力フォームを空で入力した際にmessage.propertiesに記述したエラーメッセージを出力するプログラムを書いています。
|
4
|
+
|
5
|
+
### 問題
|
6
|
+
|
7
|
+
Entityクラスのフィールド変数の中で、@NotNull private Date regist;のエラーメッセージの出力がデフォルト表示になってしまっています。
|
8
|
+
|
9
|
+
Failed to convert property value of type java.lang.String to required type java.sql.Date for property regist; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.validation.constraints.NotNull java.sql.Date] for value '; nested exception is java.lang.IllegalArgumentException
|
10
|
+
|
11
|
+
|
22
12
|
|
23
13
|
### 原因の予想
|
24
14
|
|
25
|
-
t
|
15
|
+
Date型に@NotNullを付与してますが、そもそもアノテーションが対応していないのかもしれません。。。
|
26
16
|
|
27
17
|
|
28
18
|
|
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
### やりたい事
|
2
2
|
|
3
|
-
|
3
|
+
現在入力フォームを空で入力した際にmessage.propertiesに記述したエラーメッセージを出力するプログラムを書いています。Entityクラスにはフィールド変数にそれぞれアノテーションを付与し、Controllerにはエラーを受け取るBindingResultを引数に
|
4
4
|
|
5
5
|
### エラーのタイミング
|
6
6
|
|
@@ -10,21 +10,19 @@
|
|
10
10
|
|
11
11
|
There was an unexpected error (type=Internal Server Error, status=500).
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
エラー内容にpage(Deta)とregist(Integer)が書かれていたのでそこのアノテーションの問題だと思い、@NotBlankや@NotNullを試しましたが同じようなエラーになりました。
|
13
|
+
An error happened during template parsing (template: "class path resource [templates/books/new.html]")
|
14
|
+
|
15
|
+
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/books/new.html]")
|
16
|
+
|
17
|
+
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241)
|
18
|
+
|
19
|
+
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100)
|
20
|
+
|
21
|
+
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:666)
|
22
|
+
|
23
|
+
### 原因の予想
|
24
|
+
|
25
|
+
tymeleafで値の受け取りができてないのかもしれませんが、原因がわかりません。
|
28
26
|
|
29
27
|
|
30
28
|
|
@@ -58,13 +56,13 @@
|
|
58
56
|
|
59
57
|
private BookService bookService;
|
60
58
|
|
61
|
-
|
59
|
+
|
62
60
|
|
63
61
|
@GetMapping
|
64
62
|
|
65
63
|
public String index(Model model) {
|
66
64
|
|
67
|
-
List<Book>
|
65
|
+
List<Book>books = bookService.findAll();
|
68
66
|
|
69
67
|
model.addAttribute("books", books);
|
70
68
|
|
@@ -72,119 +70,115 @@
|
|
72
70
|
|
73
71
|
}
|
74
72
|
|
75
|
-
|
76
|
-
|
77
|
-
|
73
|
+
private Map<String, String> selectCategory;
|
78
|
-
|
79
|
-
|
80
|
-
|
74
|
+
|
81
|
-
|
75
|
+
public Map<String, String> getSelectCategory(){
|
82
|
-
|
76
|
+
|
83
|
-
|
77
|
+
Map<String, String> category = new LinkedHashMap<String, String>();
|
84
|
-
|
78
|
+
|
85
|
-
|
79
|
+
category.put("A", "教育・自己啓発");
|
86
|
-
|
80
|
+
|
87
|
-
|
81
|
+
category.put("B", "小説");
|
88
|
-
|
82
|
+
|
89
|
-
|
83
|
+
category.put("C", "コミックス");
|
90
|
-
|
84
|
+
|
91
|
-
|
85
|
+
category.put("D", "ビジネス・経済");
|
92
|
-
|
86
|
+
|
93
|
-
|
87
|
+
category.put("E", "暮らし・健康・料理");
|
88
|
+
|
89
|
+
category.put("F", "ライトノベル");
|
94
90
|
|
95
91
|
return category;
|
96
92
|
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
@GetMapping("new")
|
98
|
+
|
99
|
+
public String newBook(@ModelAttribute Book book,Model model) {
|
100
|
+
|
101
|
+
selectCategory = getSelectCategory();
|
102
|
+
|
103
|
+
model.addAttribute("selectCategory", selectCategory);
|
104
|
+
|
105
|
+
return "books/new";
|
106
|
+
|
97
107
|
}
|
98
108
|
|
99
|
-
|
100
|
-
|
109
|
+
|
110
|
+
|
101
|
-
@GetMapping("
|
111
|
+
@GetMapping("{id}/edit")
|
102
|
-
|
112
|
+
|
103
|
-
public String
|
113
|
+
public String edit(@PathVariable Long id, Model model) {
|
104
|
-
|
114
|
+
|
105
|
-
|
115
|
+
Book book = bookService.findOne(id);
|
106
|
-
|
116
|
+
|
107
|
-
model.addAttribute("
|
117
|
+
model.addAttribute("book", book);
|
108
|
-
|
118
|
+
|
109
|
-
return "books/
|
119
|
+
return "books/edit";
|
110
120
|
|
111
121
|
}
|
112
122
|
|
113
|
-
|
114
|
-
|
123
|
+
|
124
|
+
|
115
|
-
|
125
|
+
@GetMapping("{id}")
|
116
|
-
|
126
|
+
|
117
|
-
|
127
|
+
public String show(@PathVariable Long id, Model model) {
|
118
|
-
|
128
|
+
|
119
|
-
|
129
|
+
Book book = bookService.findOne(id);
|
120
|
-
|
130
|
+
|
121
|
-
|
131
|
+
model.addAttribute("book", book);
|
122
|
-
|
132
|
+
|
123
|
-
|
133
|
+
return "books/show";
|
124
|
-
|
134
|
+
|
125
|
-
|
135
|
+
}
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
136
|
+
|
130
|
-
|
131
|
-
|
137
|
+
|
132
|
-
|
133
|
-
|
138
|
+
|
134
|
-
|
135
|
-
model.addAttribute("book", book);
|
136
|
-
|
137
|
-
return "books/show";
|
138
|
-
|
139
|
-
}
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
139
|
+
@PostMapping
|
144
|
-
|
140
|
+
|
145
|
-
|
141
|
+
public String create(@ModelAttribute @Validated Book book, BindingResult bindingResult, Model model) {
|
146
|
-
|
147
|
-
|
142
|
+
|
148
|
-
|
149
|
-
// 入力チェックに引っかかった場合、newに戻る
|
150
|
-
|
151
|
-
|
143
|
+
if(bindingResult.hasErrors()) {
|
152
|
-
|
153
|
-
// GETリクエスト用のメソッドを呼び出して、ユーザー登録画面に戻る
|
154
144
|
|
155
145
|
return newBook(book,model);
|
156
146
|
|
157
147
|
}
|
158
148
|
|
149
|
+
bookService.save(book);
|
150
|
+
|
159
|
-
|
151
|
+
return "redirect:/books";
|
160
|
-
|
152
|
+
|
153
|
+
|
154
|
+
|
161
|
-
|
155
|
+
}
|
162
|
-
|
163
|
-
|
164
|
-
|
156
|
+
|
157
|
+
|
158
|
+
|
165
|
-
|
159
|
+
@PutMapping("{id}")
|
166
|
-
|
160
|
+
|
167
|
-
|
161
|
+
public String update(@PathVariable Long id, @ModelAttribute Book book) {
|
168
|
-
|
162
|
+
|
169
|
-
|
163
|
+
book.setId(id);
|
170
|
-
|
164
|
+
|
171
|
-
|
165
|
+
bookService.save(book);
|
172
|
-
|
166
|
+
|
173
|
-
|
167
|
+
return "redirect:/books";
|
174
|
-
|
168
|
+
|
175
|
-
|
169
|
+
}
|
176
|
-
|
177
|
-
|
178
|
-
|
170
|
+
|
171
|
+
|
172
|
+
|
179
|
-
|
173
|
+
@DeleteMapping("{id}")
|
180
|
-
|
174
|
+
|
181
|
-
|
175
|
+
public String destroy(@PathVariable Long id) {
|
182
|
-
|
176
|
+
|
183
|
-
|
177
|
+
bookService.delete(id);
|
184
|
-
|
178
|
+
|
185
|
-
|
179
|
+
return "redirect:/books";
|
186
|
-
|
180
|
+
|
187
|
-
|
181
|
+
}
|
188
182
|
|
189
183
|
}
|
190
184
|
|
@@ -230,8 +224,6 @@
|
|
230
224
|
|
231
225
|
private Date regist;
|
232
226
|
|
233
|
-
//private byte[] cover;
|
234
|
-
|
235
227
|
|
236
228
|
|
237
229
|
@Override
|
@@ -312,97 +304,85 @@
|
|
312
304
|
|
313
305
|
<form th:action="@{/books}" th:method="post" th:object="${book}">
|
314
306
|
|
315
|
-
<!-- エラー用のCSS -->
|
307
|
+
<!-- エラー用のCSS -->
|
308
|
+
|
316
|
-
|
309
|
+
<div class="form-group"
|
310
|
+
|
317
|
-
|
311
|
+
th:classappend="${#fields.hasErrors('title')}?'has-error'">
|
318
|
-
|
312
|
+
|
319
|
-
<label class="control-label">タイトル</label>
|
313
|
+
<label class="control-label">タイトル</label>
|
320
|
-
|
314
|
+
|
321
|
-
|
315
|
+
<input class="form-control" type="text" name="title" /> <span
|
322
|
-
|
323
|
-
|
316
|
+
|
324
|
-
|
325
|
-
|
317
|
+
class="text-danger" th:if="${#fields.hasErrors('title')}"
|
318
|
+
|
326
|
-
|
319
|
+
th:errors="*{title}">userIderror</span>
|
327
|
-
|
328
320
|
|
329
321
|
</div>
|
330
322
|
|
331
|
-
|
332
|
-
|
333
323
|
<!-- エラー用のCSS -->
|
334
324
|
|
325
|
+
<div class="form-group"
|
326
|
+
|
335
|
-
|
327
|
+
th:classappend="${#fields.hasErrors('person')}?'has-error'">
|
336
|
-
|
328
|
+
|
337
|
-
<label class="control-label">著者</label>
|
329
|
+
<label class="control-label">著者</label>
|
338
|
-
|
330
|
+
|
339
|
-
type="text" name="person" />
|
331
|
+
<input class="form-control" type="text" name="person" /> <span class="text-danger"
|
340
|
-
|
341
|
-
|
332
|
+
|
342
|
-
|
343
|
-
|
333
|
+
th:if="${#fields.hasErrors('person')}" th:errors="*{person}">userIderror</span>
|
344
|
-
|
345
|
-
|
346
334
|
|
347
335
|
</div>
|
348
336
|
|
349
|
-
<
|
337
|
+
<div class="form-group"
|
350
|
-
|
338
|
+
|
351
|
-
|
339
|
+
th:classappend="${#fields.hasErrors('page')}?'has-error'">
|
352
|
-
|
340
|
+
|
353
|
-
<label class="control-label">ページ数</label>
|
341
|
+
<label class="control-label">ページ数</label>
|
354
|
-
|
342
|
+
|
355
|
-
|
343
|
+
<input class="form-control" type="number" name="page" /> <span
|
356
|
-
|
357
|
-
|
344
|
+
|
358
|
-
|
359
|
-
|
345
|
+
class="text-danger" th:if="${#fields.hasErrors('page')}"
|
346
|
+
|
347
|
+
th:errors="*{page}">userIderror</span>
|
360
348
|
|
361
349
|
</div>
|
362
350
|
|
363
|
-
<!--プルダウン
|
351
|
+
<!-- プルダウン -->
|
364
|
-
|
352
|
+
|
365
|
-
<div class="form-group"
|
353
|
+
<div class="form-group"
|
366
|
-
|
367
|
-
|
354
|
+
|
368
|
-
|
369
|
-
class="form-control" type="text" name="category" />
|
370
|
-
|
371
|
-
</div> -->
|
372
|
-
|
373
|
-
<!-- プルダウンバージョン -->
|
374
|
-
|
375
|
-
<!-- エラー用のCSS -->
|
376
|
-
|
377
|
-
|
355
|
+
th:classappend="${#fields.hasErrors('selectCategory')}?'has-error'">
|
378
356
|
|
379
357
|
<select class="form-control" id="singleSelect" name="selectCategory">
|
380
358
|
|
381
359
|
<option value="">カテゴリ</option>
|
382
360
|
|
361
|
+
<option th:each="category : ${selectCategory}"
|
362
|
+
|
383
|
-
|
363
|
+
th:value="${category.value}" th:text="${category.value}"
|
384
|
-
|
385
|
-
th:text="${category.value}"
|
386
364
|
|
387
365
|
th:selected="${category.value} == *{selectCategory}">singleSelect</option>
|
388
366
|
|
389
|
-
</select>
|
367
|
+
</select> <span class="text-danger"
|
390
|
-
|
368
|
+
|
391
|
-
|
369
|
+
th:if="${#fields.hasErrors('selectCategory')}"
|
392
|
-
|
370
|
+
|
393
|
-
|
371
|
+
th:errors="*{selectCategory}">userIderror</span>
|
394
372
|
|
395
373
|
</div>
|
396
374
|
|
397
|
-
|
375
|
+
<div class="form-group"
|
398
|
-
|
376
|
+
|
399
|
-
|
377
|
+
th:classappend="${#fields.hasErrors('regist')}?'has-error'">
|
400
|
-
|
378
|
+
|
401
|
-
<label class="form-control-label">登録日</label>
|
379
|
+
<label class="form-control-label">登録日</label>
|
402
|
-
|
380
|
+
|
403
|
-
|
381
|
+
<input class="form-control" type="date" name="regist" /> <span
|
404
|
-
|
382
|
+
|
405
|
-
|
383
|
+
class="text-danger" th:if="${#fields.hasErrors('regist')}"
|
384
|
+
|
385
|
+
th:errors="*{regist}">userIderror</span>
|
406
386
|
|
407
387
|
</div>
|
408
388
|
|