/users/list页面显示不出来
来源:5-18 -Thymeleaf实战-前台编码-02
秋风紫雨
2017-11-20
5-18 http://localhost:8080/users 页面显示不出来.
UserController自己敲的不行,拷贝项目里面的代码也不行.
注释其他方法之前异常.
注释代码后异常.
UserController类
package com.rain.spring.boot.blog.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.ModelAndView; import com.rain.spring.boot.blog.domain.User; import com.rain.spring.boot.blog.repository.UserRepository; /** * 用户控制器. * * @author <a href="https://waylau.com">Way Lau</a> * @date 2017年2月26日 */ @RestController @RequestMapping("/users") public class UserController { @Autowired private UserRepository userRepository; /** * 从 用户存储库 获取用户列表 * @return */ private List<User> getUserlist() { return userRepository.listUsers(); } /** * 查询所用用户 * @return */ @GetMapping public ModelAndView list(Model model) { model.addAttribute("userList", getUserlist()); model.addAttribute("title", "用户管理"); return new ModelAndView("users/list", "userModel", model); } /** * 根据id查询用户 * @param message * @return */ @GetMapping("{id}") public ModelAndView view(@PathVariable("id") Long id, Model model) { User user = userRepository.getUserById(id); model.addAttribute("user", user); model.addAttribute("title", "查看用户"); return new ModelAndView("users/view", "userModel", model); } /** * 获取 form 表单页面 * @param user * @return */ @GetMapping("/form") public ModelAndView createForm(Model model) { model.addAttribute("user", new User()); model.addAttribute("title", "创建用户"); return new ModelAndView("users/form", "userModel", model); } /** * 新建用户 * @param user * @param result * @param redirect * @return */ @PostMapping public ModelAndView create(User user) { user = userRepository.saveOrUpdateUser(user); return new ModelAndView("redirect:/users"); } /** * 删除用户 * @param id * @return */ @GetMapping(value = "delete/{id}") public ModelAndView delete(@PathVariable("id") Long id, Model model) { userRepository.deleteUser(id); model.addAttribute("userList", getUserlist()); model.addAttribute("title", "删除用户"); return new ModelAndView("users/list", "userModel", model); } /** * 修改用户 * @param user * @return */ @GetMapping(value = "modify/{id}") public ModelAndView modifyForm(@PathVariable("id") Long id, Model model) { User user = userRepository.getUserById(id); model.addAttribute("user", user); model.addAttribute("title", "修改用户"); return new ModelAndView("users/form", "userModel", model); } }
写回答
2回答
-
秋风紫雨
提问者
2017-11-20
你好,这是目录结构
00 -
老卫
2017-11-20
项目的目录结构是怎么样的?
082017-11-22
基于Spring Boot技术栈博客系统企业级前后端实战
毕设 Elasticsearch搜索+Thymeleaf模板+JPA+Security+BootStrap
1296 学习 · 738 问题
相似问题