index**页面**:

    1. <!DOCTYPE html>
    2. <html lang="en" xmlns:th="http://www.thymeleaf.org">
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>Title</title>
    6. </head>
    7. <body>
    8. <h1>首页</h1>
    9. <a th:href="@{/testModel}">获取request域中的数据</a><br>
    10. </body>
    11. </html>

    controller:

    1. package com.way.controller;
    2. import com.way.pojo.User;
    3. import org.springframework.stereotype.Controller;
    4. import org.springframework.ui.Model;
    5. import org.springframework.web.bind.annotation.RequestMapping;
    6. import org.springframework.web.servlet.ModelAndView;
    7. import javax.servlet.http.HttpServletRequest;
    8. @Controller
    9. public class MyController2 {
    10. @RequestMapping(value = "/testModel")
    11. public String testUser(Model model){
    12. model.addAttribute("key1","value1");
    13. model.addAttribute("key2","value2");
    14. return "target";
    15. }
    16. }

    target页面:

    1. <!DOCTYPE html>
    2. <html lang="en" xmlns:th="http://www.thymeleaf.org">
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>Title</title>
    6. </head>
    7. <body>
    8. <h1>target页面</h1>
    9. <p th:text="${key1}"></p><!--key1:是controller中request域中的key1,获取对应的value-->
    10. <p th:text="${key1}"></p><!--key1:是controller中request域中的key2,获取对应的value-->
    11. </body>
    12. </html>

    浏览器输出结果:
    image.png