1. 程式人生 > >springboot專案之controller層通過Model物件傳值到對應的返回頁面,返回頁面通過thymeleaf模板引擎來接收傳來的值

springboot專案之controller層通過Model物件傳值到對應的返回頁面,返回頁面通過thymeleaf模板引擎來接收傳來的值

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>