在控制器方法中,通过类似 RequestHeader(value="Accept-Lanaguage") String lan 可以获取请求头信息。

 

控制器方法:

SpringMVC(十) RequestMapping RequestHeader注解_spring
package com.tiekui.springmvc.handlers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller

public class RequestHeaderTest {
    
    @RequestMapping("testRequestHeader")
    public String testRequestHeader(@RequestHeader(value="Accept-Language") String language) {
        System.out.println(language);
        return "success";
    }
    
    
}
SpringMVC(十) RequestMapping RequestHeader注解_spring

 

视图内容

<a href="testRequestHeader">TestRequestHeader-video9</a>
[ 尐鱼儿的QQ群:726994578 ] --- [ https://github.com/godmaybelieve ]