以下网址查询数据库,并正确使用requestParam如下返回的所有值:如何为URL设置RequestMapping默认值/必需值?
http://localhost:8080/app/locateUser/search?firstname=John&lastname=Clay&id=2
@RequestParam(value = "firstname") String firstname,
@RequestParam(value = "lastname") String lastname,
@RequestParam(value = "id") int id
现在我想让姓氏可选(从URL中移除)在这样的:
http://localhost:8080/app/locateUser/search?firstname=John&id=2
或
http://localhost:8080/app/locateUser/search?firstname=John&lastname=&id=2
如何让网址 可选的?我希望能够在URL字符串中查询没有姓氏的数据库。
这是我有:
@RequestParam(value = "firstname") String firstname,
@RequestParam(value = "lastname" defaultValue = "lname") String lastname,
@RequestParam(value = "id") int id
我也试过
@RequestParam(value = "lastname" required=false) String lastname,
似乎都不工作。我错过了什么?
应该用'=需要FALSE'工作,告诉我们您的完整方法签名,你有错误,它可能有助于理解你的问题 –
什么是不工作...当需要'= FALSE '然后你得到一个空字符串不为空,你当然必须做更多的事情,以忽略查询中的空参数... –
这可能有助于http://stackoverflow.com/questions/17647214/form-值为空null-in-in-in-in- –