params 参数详解
例如:@GetMapping(value = "/service", params = "serviceName=CREATE_PROJECT")
1.包含某个参数(请求数据中有指定参数名)
必须包含参数name,name有没有值无所谓,只要包含参数名name就可以
@RequestMapping("/request_param")
@Controller
public class RequestParamController {
//请求数据中有指定的参数
//必须包含参数name,name有没有值无所谓,只要包含参数名name就可以
@RequestMapping(value="/test1",params= {"name"})
public String test1() {
System.out.println("RequestParamController test1()...");
return "test";//跳转到test.jsp
}
}
这些都可以访问
http://127.0.0.1:9999/springmvc/request_param/test1?name
http://127.0.0.1:9999/springmvc/request_param/test1?name=tom
http://127.0.0.1:9999/springmvc/request_param/test1?name=tom&password=123
2.不包含某个参数(请求数据中没有指定参数名)
只要不包含参数名name就可以
@RequestMapping("/request_param")
@Controller
public class RequestParamController {
//只要不包含参数名name就可以
@RequestMapping(value="/test2",params= {"!name"})
public String test2() {
System.out.println("RequestParamController test2()...");
return "test";//跳转到test.jsp
}
}
这些都可以访问
http://127.0.0.1:9999/springmvc/request_param/test2
http://127.0.0.1:9999/springmvc/request_param/test1?id=9
3.请求数据中指定参数名=值
只要参数名有name=tom的就可以
@RequestMapping("/request_param")
@Controller
public class RequestParamController {
@RequestMapping(value="/test3",params= {"name=tom"})
public String test3() {
System.out.println("RequestParamController test3()...");
return "test";//跳转到test.jsp
}
}
这些都可以访问
http://127.0.0.1:9999/springmvc/request_param/test3?name=tom
http://127.0.0.1:9999/springmvc/request_param/test3?name=tom&password=123
4.请求数据中指定参数名!=值
没有参数name也行,有name没有值也行,name不能为tom
@RequestMapping("/request_param")
@Controller
public class RequestParamController {
@RequestMapping(value="/test4",params= {"name!=tom"})
public String test4() {
System.out.println("RequestParamController test4()...");
return "test";//跳转到test.jsp
}
}
这些都可以访问
http://127.0.0.1:9999/springmvc/request_param/test4
http://127.0.0.1:9999/springmvc/request_param/test4?id=9
http://127.0.0.1:9999/springmvc/request_param/test4?name
http://127.0.0.1:9999/springmvc/request_param/test4?name=jack
5.组合使用是"且"的关系
之间用&
@RequestMapping("/request_param")
@Controller
public class RequestParamController {
//必须有id参数,name不能为tom
@RequestMapping(value="/test5",params= {"id","name!=tom"})
public String test5() {
System.out.println("RequestParamController test5()...");
return "test";//跳转到test.jsp
}
}
这些都可以访问
http://127.0.0.1:9999/springmvc/request_param/test5?id
http://127.0.0.1:9999/springmvc/request_param/test5?id=5&name
http://127.0.0.1:9999/springmvc/request_param/test5?id=5&name=jack