@RequestParam和request.getParamter和request.getParamterMap的用法及区别
@RequestParam
该注解是用于获取在get 方式中queryString的值,和Content-Type为application/x-www-form-urlencoded的post方式中 body data的值。
request.getParamter(String s)
该方法和上面的注解功能相同,也是用来获取get或post方式传递的参数值,输出结果为String类型
request.getParamterMap()
该方法是获取get或post提交的所有参数,并转为一个map,key是String类型,value是String数组,用来保存相同key的所有value。
例子:
get请求:http://localhost:8088/paramTest.do?id=1&name=szj&name=wly
结果为:
可以看到,get请求参数id被注解和getParamter捕获,所有参数被getParamtermap()捕获,并且相同key,value被存为数组。
post方式:
结果: