SpringMV---params and headers

  配置文件承接一二章

   params

    params:请求的参数
    params=value 表示请求过来的参数必须等于value
    params!=value 表示请求过来的参数必须不等于value
    {params = vlaue1 ,params !=value2 }也可以写成数组的形式。
  

   headers

    headers:请求头
    每个浏览器的请求头是不同的,所以我们可以通过请求头的不同来区分浏览器。

  index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello World</title>
</head>
<body>
 

 <form action="springMVC/test4Param" method="get">
 <input type="text" name="username"/>
 <input type="text" name="age"/>
 <input type="submit" value="submit"/>
 </form>
 

</body>
</html>

test.java

package com.hdxy.domian;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
/**
 * @author 流年拓荒者
 *
 */
@RequestMapping("springMVC")
@Controller
public class Test {
   final public String SUCCESS="loginSuccess";
   /*params:请求的参数
    params=value 表示请求过来的参数必须等于value
    params!=value 表示请求过来的参数必须不等于value
    {params = vlaue1 ,params !=value2 }也可以写成数组的形式。*/
   @RequestMapping(value="test4Param",params={"username","age!=10"})
    public String test4Param(){
        System.out.println("test4Param");
        return SUCCESS;
    }
}
流年拓荒者
原文地址:https://www.cnblogs.com/lnthz/p/7865511.html