質問編集履歴
3
コントローラーの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -56,7 +56,7 @@
|
|
56
56
|
List<Company> company = empService.getCompanyAll();
|
57
57
|
model.addAttribute("company", company);
|
58
58
|
|
59
|
-
return "
|
59
|
+
return "edit";
|
60
60
|
}
|
61
61
|
|
62
62
|
//従業員情報の更新処理(ここは正しく動く)
|
2
従業員更新処理のif (bindingResult.hasErrors()) {}内をModelに受け渡す形で修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -48,8 +48,13 @@
|
|
48
48
|
@PostMapping("/employeeDetail/{id}/update")
|
49
49
|
public String postUpdate(@Validated Employee employee,BindingResult bindingResult,RedirectAttributes attributes,Model model,@PathVariable("id") String id) {
|
50
50
|
if (bindingResult.hasErrors()) {
|
51
|
+
employee = empService.selectOne(id);
|
51
|
-
|
52
|
+
attributes.addFlashAttribute("org.springframework.validation.BindingResult.employee", bindingResult);
|
52
|
-
|
53
|
+
attributes.addFlashAttribute("employee", employee);
|
54
|
+
|
55
|
+
//法人のプルダウンリスト表示
|
56
|
+
List<Company> company = empService.getCompanyAll();
|
57
|
+
model.addAttribute("company", company);
|
53
58
|
|
54
59
|
return "redirect:/employeeDetail/{id}/edit";
|
55
60
|
}
|
1
コントローラーの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,7 +28,7 @@
|
|
28
28
|
@Autowired
|
29
29
|
JdbcTemplate jdbcTemplate;
|
30
30
|
|
31
|
-
//編集画面の表示のGETメソッド
|
31
|
+
//編集画面の表示のGETメソッド
|
32
32
|
@GetMapping("/employeeDetail/{id}/edit")
|
33
33
|
public String displayEdit(@PathVariable("id") String id, Model model) {
|
34
34
|
//バリデーションエラーが出た場合データを保持した状態で表示する
|
@@ -44,7 +44,7 @@
|
|
44
44
|
return "edit";
|
45
45
|
}
|
46
46
|
|
47
|
-
//更新処理のPOSTメソッド
|
47
|
+
//更新処理のPOSTメソッド
|
48
48
|
@PostMapping("/employeeDetail/{id}/update")
|
49
49
|
public String postUpdate(@Validated Employee employee,BindingResult bindingResult,RedirectAttributes attributes,Model model,@PathVariable("id") String id) {
|
50
50
|
if (bindingResult.hasErrors()) {
|
@@ -52,10 +52,17 @@
|
|
52
52
|
attributes.addFlashAttribute("employee", employee);
|
53
53
|
|
54
54
|
return "redirect:/employeeDetail/{id}/edit";
|
55
|
-
|
56
|
-
↓更新処理(省略)
|
57
55
|
}
|
58
56
|
|
57
|
+
//従業員情報の更新処理(ここは正しく動く)
|
58
|
+
jdbcTemplate.update("update m_employee set name = ?,telephone_number = ?,mail_address = ?,company_id = ? where id = " + id,
|
59
|
+
employee.getName(),
|
60
|
+
employee.getTelephonenumber(),
|
61
|
+
employee.getMailaddress(),
|
62
|
+
employee.getCompany_id());
|
63
|
+
|
64
|
+
return "redirect:/employeeDetail/{id}";
|
65
|
+
}
|
59
66
|
}
|
60
67
|
```
|
61
68
|
```HTML
|