RequestParam value in spring MVC to be case insensitive
It might be nice for Spring to support this, but I can also understand why they wouldn't since it could result in a weakening of an interface contract between a supplier and consumer. In the meantime, here's a fairly straightforward way to take the first value using the parameter name regardless of its case.
String myVal = null;
for (String pname : request.getParameterMap().keySet() ) {
if ( pname != null && pname.toLowerCase().equals("your_lc_pname") ) {
for (String v : request.getParameterValues(pname) ) {
// do something with your value(s)
}
}
}
Another approach would be to have two parameters "orgId" and "orgid" and have the optional.
public String welcome(@RequestParam(value="orgID", required = false) String org_ID, @RequestParam(value="orgid", required=false, String orgid, ModelMap model) {
final String orgId = orgid == null ? org_ID : orgid;
...
}
But if you have control over the parameters I would strongly prefer to just have one consistent way, say org-id and follow it both in the client and the server side.