RequestParam value in spring MVC to be case insensitive

前端 未结 6 2138
离开以前
离开以前 2021-01-17 20:40

Am sending data from JSP to controller using query string.

My controller is annotation driven.

The value of the the request parameter should be case-insensit

6条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-17 21:03

    The simplest way I found was to change the controller method to take a Map with a single key value pair as a parameter and then convert the key to lowercase.

    public String welcome(@RequestParam(required = true) Map params, ModelMap model) {
       String caseInsensitiveOrgId = params.keySet().toArray()[0].toString().toLowerCase();
       String OrgValue = params.values().toArray()[0];
       // Do whatever you want here
    }
    

提交回复
热议问题