首页 > 代码库 > SpringMVC(十) RequestMapping RequestHeader注解

SpringMVC(十) RequestMapping RequestHeader注解

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

 

控制器方法:

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="http://www.mamicode.com/Accept-Language") String language) {
        System.out.println(language);
        return "success";
    }
    
    
}

 

视图内容

<a href="http://www.mamicode.com/testRequestHeader">TestRequestHeader-video9</a>

 

SpringMVC(十) RequestMapping RequestHeader注解