Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 全体队员名单_Spring_List_Rest_Spring Mvc_Thymeleaf - Fatal编程技术网

Spring 全体队员名单

Spring 全体队员名单,spring,list,rest,spring-mvc,thymeleaf,Spring,List,Rest,Spring Mvc,Thymeleaf,我想显示所有现有团队的列表,但在屏幕上我只看到我添加的最后一个团队 未显示先前创建并位于存储库中的团队 teamList.html <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <

我想显示所有现有团队的列表,但在屏幕上我只看到我添加的最后一个团队

未显示先前创建并位于存储库中的团队

teamList.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>Team List</h1>
<br/><br/>
<div>
    <table border="1">
        <tr>
            <th>Team Name</th>
            <th>Team Url</th>

        </tr>
        <tr th:each ="tm : ${teamForm}">
            <td th:utext="${tm.name}">...</td>
            <td th:utext="${tm.url}">...</td>
        </tr>
    </table>
</div>
<button type="button" onclick="window.history.go(-1);">Back</button>

</body>
</html>
管理员控制器

我使用rest重定向页面

也许他没有从存储库中获取所有数据

@Controller
public class AdminController {

    @Autowired
    TeamRepository teamRepository;


    @GetMapping("/admin/team/all")
    List<Team> allTeams() {
        return teamRepository.findAll();
    }
  @RequestMapping(value = "/admin/team", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public String addTeam(Model model, @ModelAttribute("teamForm") @Validated TeamForm teamForm,
            BindingResult result, final RedirectAttributes redirectAttributes) {
        System.out.println("addTeam invoked");
        Team newTeam = new Team();
        newTeam.setName(teamForm.getName());
        newTeam.setUrl(teamForm.getUrl());
        teamRepository.save(newTeam);
        return "teamList";
    }

 @RequestMapping(value = "/admin/team" , method = RequestMethod.GET)
    public String teamList(Model model) {
        model.addAttribute("teamForm", allTeams());
        return "teamList";
    }

   @RequestMapping(value = "/admin", method = RequestMethod.GET)
    public String adminPage(Model model) {
         model.addAttribute("teamForm",new TeamForm());
        model.addAttribute("eventForm",new EventForm());
        return "admin";
    }
@控制器
公共类管理员控制器{
@自动连线
团队知识库团队知识库;
@GetMapping(“/admin/team/all”)
列出所有团队(){
返回teamRepository.findAll();
}
@RequestMapping(value=“/admin/team”,method=RequestMethod.POST,products=MediaType.APPLICATION\u JSON\u value)
公共字符串addTeam(模型模型,@modeldattribute(“teamForm”)@validatedteamformteamform,
BindingResult结果,最终重定向属性(重定向属性){
System.out.println(“addTeam调用”);
团队新团队=新团队();
setName(teamForm.getName());
setUrl(teamForm.getUrl());
teamRepository.save(新团队);
返回“团队列表”;
}
@RequestMapping(value=“/admin/team”,method=RequestMethod.GET)
公共字符串团队列表(模型){
addAttribute(“teamForm”,allTeams());
返回“团队列表”;
}
@RequestMapping(value=“/admin”,method=RequestMethod.GET)
公共字符串adminPage(模型){
addAttribute(“teamForm”,new teamForm());
addAttribute(“eventForm”,new eventForm());
返回“admin”;
}

您请求哪一页?
/admin
/admin/team
?我想显示在这里/admin/team
@Controller
public class AdminController {

    @Autowired
    TeamRepository teamRepository;


    @GetMapping("/admin/team/all")
    List<Team> allTeams() {
        return teamRepository.findAll();
    }
  @RequestMapping(value = "/admin/team", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public String addTeam(Model model, @ModelAttribute("teamForm") @Validated TeamForm teamForm,
            BindingResult result, final RedirectAttributes redirectAttributes) {
        System.out.println("addTeam invoked");
        Team newTeam = new Team();
        newTeam.setName(teamForm.getName());
        newTeam.setUrl(teamForm.getUrl());
        teamRepository.save(newTeam);
        return "teamList";
    }

 @RequestMapping(value = "/admin/team" , method = RequestMethod.GET)
    public String teamList(Model model) {
        model.addAttribute("teamForm", allTeams());
        return "teamList";
    }

   @RequestMapping(value = "/admin", method = RequestMethod.GET)
    public String adminPage(Model model) {
         model.addAttribute("teamForm",new TeamForm());
        model.addAttribute("eventForm",new EventForm());
        return "admin";
    }