質問編集履歴
1
HeloController.javaにindex※を追記。文字数上form部分削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,9 +34,9 @@
|
|
34
34
|
|
35
35
|
### 該当のソースコード
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
MyDataService.java
|
38
|
+
|
39
|
+
```Java
|
40
40
|
|
41
41
|
package com.tuyano.springboot;
|
42
42
|
|
@@ -134,9 +134,9 @@
|
|
134
134
|
|
135
135
|
```
|
136
136
|
|
137
|
-
|
138
|
-
|
139
|
-
|
137
|
+
MyDataRepository.java
|
138
|
+
|
139
|
+
```Java
|
140
140
|
|
141
141
|
package com.tuyano.springboot.repositories;
|
142
142
|
|
@@ -176,9 +176,9 @@
|
|
176
176
|
|
177
177
|
```
|
178
178
|
|
179
|
-
|
180
|
-
|
181
|
-
|
179
|
+
HeloController.java
|
180
|
+
|
181
|
+
```Java
|
182
182
|
|
183
183
|
package com.tuyano.springboot;
|
184
184
|
|
@@ -248,6 +248,36 @@
|
|
248
248
|
|
249
249
|
}
|
250
250
|
|
251
|
+
//
|
252
|
+
|
253
|
+
// index※追記
|
254
|
+
|
255
|
+
//
|
256
|
+
|
257
|
+
@RequestMapping(value = "/page/{num}", method = RequestMethod.GET)
|
258
|
+
|
259
|
+
public ModelAndView page(@PathVariable Integer num,
|
260
|
+
|
261
|
+
ModelAndView mav) {
|
262
|
+
|
263
|
+
Page<MyData> page = service.getMyDataInPage(num);
|
264
|
+
|
265
|
+
mav.setViewName("index");
|
266
|
+
|
267
|
+
mav.addObject("title", "Find Page");
|
268
|
+
|
269
|
+
mav.addObject("msg", "MyDataのサンプル。");
|
270
|
+
|
271
|
+
mav.addObject("pagenumber", num);
|
272
|
+
|
273
|
+
mav.addObject("datalist", page);
|
274
|
+
|
275
|
+
return mav;
|
276
|
+
|
277
|
+
}
|
278
|
+
|
279
|
+
|
280
|
+
|
251
281
|
// find
|
252
282
|
|
253
283
|
@RequestMapping(value = "/find", method = RequestMethod.GET)
|
@@ -300,46 +330,6 @@
|
|
300
330
|
|
301
331
|
}
|
302
332
|
|
303
|
-
// form
|
304
|
-
|
305
|
-
@RequestMapping(value = "/", method = RequestMethod.POST)
|
306
|
-
|
307
|
-
@Transactional(readOnly = false)
|
308
|
-
|
309
|
-
public ModelAndView form(
|
310
|
-
|
311
|
-
@ModelAttribute("formModel") @Validated MyData mydata,
|
312
|
-
|
313
|
-
BindingResult result,
|
314
|
-
|
315
|
-
ModelAndView mov) { // バリデーションチェックの結果を調べる。
|
316
|
-
|
317
|
-
ModelAndView res = null;
|
318
|
-
|
319
|
-
if (!result.hasErrors()) { // エラーじゃなかった(true)場合
|
320
|
-
|
321
|
-
repository.saveAndFlush(mydata);
|
322
|
-
|
323
|
-
res = new ModelAndView("redirect:/");
|
324
|
-
|
325
|
-
} else { // エラーの場合
|
326
|
-
|
327
|
-
mov.setViewName("index");
|
328
|
-
|
329
|
-
mov.addObject("msg", "sorry, error is occred...");
|
330
|
-
|
331
|
-
Iterable<MyData> list = repository.findAll();
|
332
|
-
|
333
|
-
mov.addObject("datalist", list);
|
334
|
-
|
335
|
-
res = mov;
|
336
|
-
|
337
|
-
}
|
338
|
-
|
339
|
-
return res;
|
340
|
-
|
341
|
-
}
|
342
|
-
|
343
333
|
// P342リスト7-12
|
344
334
|
|
345
335
|
@Autowired
|
@@ -506,9 +496,9 @@
|
|
506
496
|
|
507
497
|
```
|
508
498
|
|
509
|
-
|
510
|
-
|
511
|
-
|
499
|
+
index.html
|
500
|
+
|
501
|
+
```Html
|
512
502
|
|
513
503
|
<!DOCTYPE html>
|
514
504
|
|