可以正常启动,但是访问就报错了,麻烦老师帮忙看下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 实体类: 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; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | 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
了解课程