说明与作用
@RequestHeader注解的作用是从请求中获取某个请求头的值,并赋值给方法形参。
@CookieValue注解的作用是从请求中获取某个Value的值,并赋值给方法形参。
控制器:
package com.awaimai.web;
import org.hibernate.validator.constraints.Range;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.HashMap;
import java.util.Map;
@Controller
@Validated
public class kzq
{
@RequestMapping(value = "/test6")
@ResponseBody
public String test6(@RequestHeader(value = "Content-Type") String contentType,@CookieValue(value = "cookie_name") String cookie_name)
{
System.out.println(contentType);
System.out.println(cookie_name);
return "springmvc";
}
}
postman访问: