Spring MVC @CookieValue注解

版权声明:最终解释权归属Hern、HernSong(hernsong)、苍鹭、www.hernsong.com所有! https://blog.csdn.net/qq_36761831/article/details/88887907

使用 @CookieValue 绑定请求中的 Cookie 值,@CookieValue 可让处理方法入参绑定某个 Cookie 值。

例如:

jsp页面

<%--
  Created by IntelliJ IDEA.
  User: 23369
  Date: 2019/3/24
  Time: 18:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
    <a href="helloworld_mvc/testcookvalue">testcookvalue</a>
  </body>
</html>

Java类

package com.helloworld;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.filter.HiddenHttpMethodFilter;

import javax.swing.text.html.HTMLDocument;

@Controller
@RequestMapping("/helloworld_mvc")
public class HelloWorld {

    @RequestMapping("testcookvalue")
    public String testcookvalue(@CookieValue("JSESSIONID") String  sessionid){
        System.out.println(sessionid);
        return "success";
    }

}

猜你喜欢

转载自blog.csdn.net/qq_36761831/article/details/88887907