|
2 | 2 |
|
3 | 3 | import java.util.Optional; |
4 | 4 |
|
| 5 | +import javax.validation.Valid; |
| 6 | + |
5 | 7 | import com.github.throyer.common.springboot.domain.pagination.service.Pagination; |
6 | 8 | import com.github.throyer.common.springboot.domain.toast.Toasts; |
7 | 9 | import com.github.throyer.common.springboot.domain.toast.Type; |
| 10 | +import com.github.throyer.common.springboot.domain.user.form.CreateOrUpdateUserByAppForm; |
8 | 11 | import com.github.throyer.common.springboot.domain.user.repository.UserRepository; |
9 | 12 | import com.github.throyer.common.springboot.domain.user.service.RemoveUserService; |
10 | 13 |
|
11 | 14 | import org.springframework.beans.factory.annotation.Autowired; |
12 | 15 | import org.springframework.security.access.prepost.PreAuthorize; |
13 | 16 | import org.springframework.stereotype.Controller; |
14 | 17 | import org.springframework.ui.Model; |
| 18 | +import org.springframework.validation.BindingResult; |
15 | 19 | import org.springframework.web.bind.annotation.GetMapping; |
16 | 20 | import org.springframework.web.bind.annotation.PathVariable; |
17 | 21 | import org.springframework.web.bind.annotation.PostMapping; |
@@ -42,6 +46,26 @@ public String index( |
42 | 46 |
|
43 | 47 | return "app/users/index"; |
44 | 48 | } |
| 49 | + |
| 50 | + @GetMapping("/form") |
| 51 | + public String form(Model model) { |
| 52 | + model.addAttribute("user", new CreateOrUpdateUserByAppForm()); |
| 53 | + return "app/users/form"; |
| 54 | + } |
| 55 | + |
| 56 | + @PostMapping(produces = "text/html") |
| 57 | + public String create( |
| 58 | + @Valid CreateOrUpdateUserByAppForm props, |
| 59 | + BindingResult validations, |
| 60 | + RedirectAttributes redirect, |
| 61 | + Model model |
| 62 | + ) { |
| 63 | + if (validations.hasErrors()) { |
| 64 | + // return "app/users/index"; |
| 65 | + } |
| 66 | + |
| 67 | + return "redirect:/app/users/form"; |
| 68 | + } |
45 | 69 |
|
46 | 70 | @PostMapping("/delete/{id}") |
47 | 71 | public String delete(@PathVariable Long id, RedirectAttributes redirect) { |
|
0 commit comments