可以正常启动,但是访问就报错了,麻烦老师帮忙看下
实体类: package com.example; public class User { private Long id; private String name; private String email; public User(){ } public User(Long id, String name, String email) { this.id = id; this.name = name; this.email = email; } public void setId(Long id) { this.id = id; } public void setName(String name) { this.name = name; } public void setEmail(String email) { this.email = email; } public Long getId() { return id; } public String getName() { return name; } public String getEmail() { return email; } }
package com.controller; import com.example.User; import com.repository.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; @RestController @RequestMapping("/users") public class UserController { @Autowired private UserRepository userRepository; @GetMapping public ModelAndView list(Model model){ model.addAttribute("list", userRepository.listUsers()); model.addAttribute("title", "用户管理"); return new ModelAndView("users/list","userModel",model); } @GetMapping("{id}") public ModelAndView view(@PathVariable("id") Long id, Model model){ model.addAttribute("user", userRepository.getUserById(id)); model.addAttribute("title", "查看用户"); return new ModelAndView("users/view", "userModel", model); } @GetMapping("/form") public ModelAndView createForm(Model model){ model.addAttribute("user",new User()); model.addAttribute("title", "创建用户"); return new ModelAndView("users/form", "userModel", model); } @PostMapping public ModelAndView saveOrUpdate(User user){ userRepository.saveOrUpdate(user); return new ModelAndView("redirect: /users"); } @GetMapping("/delete/{id}") public ModelAndView delete(@PathVariable("id") Long id){ userRepository.deleteUser(id); return new ModelAndView("redirect: /users"); } @GetMapping("/modify/{id}") public ModelAndView modify(@PathVariable("id") Long id, Model model){ model.addAttribute("user", userRepository.getUserById(id)); model.addAttribute("title", "修改用户"); return new ModelAndView("users/form", "userModel", model); } }
毕设 Elasticsearch搜索+Thymeleaf模板+JPA+Security+BootStrap
了解课程