addUser.html

<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org" lang="ru"> <head> <title>CRUDSpringBoot</title> </head> <body> <div th:fragment="content"> //Вместе с th:fragment не хочет работать <p>привет я addUser</p> <form method="post" th:object="${user}" th:action="@{/admin/add}" > <label for="name" > Name </label> <input id="name" type="text" th:field="${user.name}"/> <label for="login"> Login </label> <input id="login" type="text" th:field="${user.login}"/> <label for="password"> Password </label> <input id="password" type="text" th:field="${user.password}"/> <button type="submit">Save</button> </form> </div> </body> </html> 

getAllUser.html

 <div class="tab-pane" id="profile"> <p>Вторая страница</p> <div th:replace="adduser :: content"></div> </div> 

ERROR in the console java.lang.IllegalStateException: Neither BindingResult nor the normal target for the bean error ERROR in the browser Whitelabel, for example, there is no fallback. Wed Feb 28 08:24:21 EET 2018 There was an unexpected error (type = Internal Server Error, status = 500). Error during execution of the processor 'org.thymeleaf.spring4.processor.attr.SpringInputGeneralFieldAttrProcessor' (adduser: 17)

    1 answer 1

    Answer your question! Since we are embedding one page into another, we need to pass the same attribute to another page. We also added the attributes adduser.html to getAlluser.html These attributes are model.addAttribute ("user", new User ());

     @Controller 

    @RequestMapping (value = "/ admin") public class AdminController {

     @Autowired private UserService userService; @RequestMapping public String getAllUser(Model model){ model.addAttribute("getAllUser", this.userService.getAllUser()); model.addAttribute("user", new User()); //Добавил эту строчку return "getAlluser"; } @RequestMapping(value = "/add", method = RequestMethod.GET) public String getAddPageUser(Model model){ model.addAttribute("user", new User()); return "adduser"; } @RequestMapping(value = "/add", method = RequestMethod.POST) public String addUser(@ModelAttribute("user") User user){ userService.addUser(user); return "redirect:/admin";