cookie是客户端的会话技术。浏览器不关闭会一直存在。
    session是服务器的会话技术。

    @CookieValue是将cookie数据和控制器方法的形参创建映射关系
    @CookieValue注解一共有三个属性:valuerequireddefaultValue,用法同@RequestParam

    示例:
    HTML:

    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="@{/cookieValue}">获取JSESSIONID</a><br>
    10. </body>
    11. </html>


    Controller:

    package com.way.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.*;
    
    import javax.servlet.http.HttpServletRequest;
    import java.util.Arrays;
    
    @Controller
    public class MyController {
    
        @RequestMapping(value = "/cookieValue")
        public String testCookieValue(@CookieValue("JSESSIONID") String jsessionId) {
            System.out.println(jsessionId);
            return "target";
        }
    }
    

    idea输出:

    D734D332FB42FFDE825573C8760E44AE