[英]spring boot load data from list
I want to put data from user list to frontend in spring but i have no idea how to do it.我想将用户列表中的数据放到 spring 中的前端,但我不知道该怎么做。 For example with static file something.json it works but how can i create it from list.
例如,使用 static 文件 something.json 它可以工作,但我如何从列表中创建它。
This is my frontend这是我的前端
<tr th:each="user: ${users}">
<td th:text="${user.id}"></td>
<td th:text="${user.firstName}"></td>
<td th:text="${user.lastName}"></td>
</tr>
and this is my spring boot main file这是我的 spring 引导主文件
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");
}
}
I am creating one employee and one user to have some data.我正在创建一名员工和一名用户来获取一些数据。 So how can I print that user (let's say there will be more users) to frontend?
那么如何将该用户(假设会有更多用户)打印到前端? Thanks for help.
感谢帮助。
U need a @Controller class wich who should have the responsibility to take your list to your html.你需要一个@Controller class,他应该负责将你的列表带到你的 html。
That class, should have a method for this: class,应该有一个方法:
@GetMapping("/all")
public String showAll(Model model) {
model.addAttribute("books", bookService.findAll());
return "books/allBooks";
}
Where "GetMapping" is ur url, Model is a object that binds the objects to ur html, and return is a path of ur html file. Where "GetMapping" is ur url, Model is a object that binds the objects to ur html, and return is a path of ur html file.
U can follow tutorial bellow for more informations: https://www.baeldung.com/thymeleaf-list您可以按照以下教程获取更多信息: https://www.baeldung.com/thymeleaf-list
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.