分享
三行代码  ›  专栏  ›  技术社区  ›  Juraj Jakubov

来自列表的弹簧引导加载数据

  •  0
  • Juraj Jakubov  · 技术社区  · 1 周前

    我想在春天把用户列表中的数据放到前端,但我不知道该怎么做。
    这是我的前端

    <tr th:each="user: ${users}">
        <td th:text="${user.id}"></td>
        <td th:text="${user.firstName}"></td>
        <td th:text="${user.lastName}"></td>
    </tr>
    

    这是我的spring boot主文件

        public static void main(String[] args) {
            Engine company = new Engine();
            User user;
            Travel travel;
            User employee;
            user = company.createUser("gfdgfd","gfdgdf",49484894,"gfdgfdg@fdgfd.com",918191,"Bratislava","Ulica",456);
            employee = company.createUser("Andrej","g",49489dgdf4,"gfdgfdg@fdgfd.com",918191,"Bratislava","Ulica",456);
            company.listUsers();
            company.listUser(user.getID());
            company.editUser(user.getID(),"Jg","g"fgfd,494848fdgfd",94,"gfdgfdg@fdgfd.com",918191,"Bratislava","Ulica",456);
            travel = company.lifeIT(employee, LocalDate.of(2020,1,1),LocalDate.of(2021,1,1),5000,100,user,false,EnumActivity.valueOf("WORK"));
            user.setContracts(travel.getID());
            company.listInsurances();
            company.listInsurance(employee.getID());
            company.editlifeIT(travel.getID(),employee, LocalDate.of(2020,1,1),LocalDate.of(2022,1,1),5000,1000,user,false,EnumActivity.valueOf("SPORT"));
    
    
            SpringApplication.run(MvcListApplication.class, args);
            log.info("Open in browser: http://localhost:8080");
        }
    }
    

    我正在创建一个雇员和一个用户来获得一些数据。那么,我如何将该用户(假设会有更多用户)打印到前端?谢谢你的帮助。

    1 回复  |  直到 1 周前
        1
  •  1
  •   Eduardo Nobre    1 周前

    @GetMapping("/all")
    public String showAll(Model model) {
     model.addAttribute("books", bookService.findAll());
     return "books/allBooks";
    }
    

    您可以按照下面的教程了解更多信息: https://www.baeldung.com/thymeleaf-list