后代编码写完后报错了
来源:5-16 -Thymeleaf实战-后台编码
慕容5410851
2018-02-13
可以正常启动,但是访问就报错了,麻烦老师帮忙看下
实体类: 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); } }
写回答
2回答
-
应该是你的 thymeleaf 版本问题吧。~根据课程的版本要求来~
042019-10-16 -
慕容5410851
提问者
2018-02-14
我的目录结构是这样的。建了list.html这个文件了
00
基于Spring Boot技术栈博客系统企业级前后端实战
毕设 Elasticsearch搜索+Thymeleaf模板+JPA+Security+BootStrap
1296 学习 · 738 问题
相似问题