Spring注解之@GetMapping详解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
}
}
这些都可以访问
127.0.0.1:9999/springmvc/request_param/test1?name
127.0.0.1:9999/springmvc/request_param/test1?name=tom
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
}
}
这些都可以访问
127.0.0.1:9999/springmvc/request_param/test2
127.0.0.1:9999/springmvc/request_param/test1?id=9
3.请求数据中指定参数名=值
只要参数名有name=tom的就可以
@RequestMapping("/request_param")
@Controller
public class RequestParamController {
springmvc的注解有哪些@RequestMapping(value="/test3",params={"name=tom"})
public String test3(){
System.out.println("RequestParamController test3()...");
return"test";//跳转到test.jsp
}
}
这些都可以访问
127.0.0.1:9999/springmvc/request_param/test3?name=tom
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
}
}
这些都可以访问
127.0.0.1:9999/springmvc/request_param/test4
127.0.0.1:9999/springmvc/request_param/test4?id=9
127.0.0.1:9999/springmvc/request_param/test4?name
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
}
}
这些都可以访问
127.0.0.1:9999/springmvc/request_param/test5?id
127.0.0.1:9999/springmvc/request_param/test5?id=5&name 127.0.0.1:9999/springmvc/request_param/test5?id=5&name=jack
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论