How to prevent parameter binding from interpreting commas in Spring 3.0.5?

后端 未结 6 1869
抹茶落季
抹茶落季 2020-11-28 06:37

Consider the following controller method:

@RequestMapping(value = \"/test\", method = RequestMethod.GET)
public void test(@RequestParam(value = \"fq\", requi         


        
6条回答
  •  不知归路
    2020-11-28 07:13

    I have found the most elegant and the shortest way for me - add @InitBinder to a @Controller:

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        binder.registerCustomEditor(String[].class, new StringArrayPropertyEditor(null));
    }
    

    It will convert String to String[] without using separator (null param), with Spring class org.springframework.beans.propertyeditors.StringArrayPropertyEditor. If someone in same project will use new default conversion way, it will be ok.

提交回复
热议问题