10.@RequestMapping中的params(请求参数映射限定)

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
  • 11
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值