springboot项目之controller层通过Model对象传值到对应的返回页面,返回页面通过thymeleaf模板引擎来接收传来的值

版权声明: https://blog.csdn.net/weixin_40550726/article/details/83030887

1.controller层的方法接收到请求后将返回borrowingBooks.html页面,并将一个List对象res的值传递到borrowingBooks.html页面。

@Controller
public class UserController {

    @Resource
    private IUserService userService;


    @RequestMapping("/userBorrowingBooksPage")
    public String userBorrowingBooksPage(Model model,HttpServletRequest request){
       List<BorrowingBooksVo> res=userService.findAllBorrowingBooks(request);
       model.addAttribute("borrowingBooksList",res);
        return "user/borrowingBooks";
    }
 

   
}

2.borrowingBooks.html页面接收值,并显示。

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>借书页面</title>
</head>
<body>
<b>借书页面</b><br>
<tr th:each="borrowingBooks : ${borrowingBooksList}">
    <td><a href="#" th:text="${borrowingBooks.getBook().getBookName()}">Title ...</a></td>
    <td th:text="${borrowingBooks.getDate()}">1</td><br>
</tr>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_40550726/article/details/83030887