请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

后代编码写完后报错了

可以正常启动,但是访问就报错了,麻烦老师帮忙看下

https://img1.sycdn.imooc.com//szimg/5a82dcc800018ad912270268.jpg

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);
    }
 
}

正在回答

插入代码

2回答

老卫 2018-02-13 21:09:52

应该是你的 thymeleaf 版本问题吧。~根据课程的版本要求来~

0 回复 有任何疑惑可以回复我~
  • 提问者 慕容5410851 #1
    我改成了一样的版本,还是报了同样的错,前台代码还没写就与报错了?
    <!-- set thymeleaf version -->
    		<thymeleaf.version>3.0.3.RELEASE</thymeleaf.version>
    		<thymeleaf-layout-dialect.version>2.2.0</thymeleaf-layout-dialect.version>
    回复 有任何疑惑可以回复我~ 2018-02-13 21:34:48
  • 老卫 回复 提问者 慕容5410851 #2
    代码要写啊~。不然,怎么找得到  users/list 页面
    回复 有任何疑惑可以回复我~ 2018-02-13 21:45:07
  • 我写了前端代码,版本一样,也是这个错。。
    回复 有任何疑惑可以回复我~ 2019-10-14 17:36:07
提问者 慕容5410851 2018-02-14 09:27:24

我的目录结构是这样的。建了list.html这个文件了https://img1.sycdn.imooc.com//szimg/5a8390750001083003120543.jpg

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号