How to do spring request parameter conversion

后端 未结 5 1527
南旧
南旧 2021-02-05 13:36

In a Spring 3 based web (portlet) application I have a controller with a method like this:

@RenderMapping
public ModelAn         


        
5条回答
  •  再見小時候
    2021-02-05 14:08

    You are correct that Converter (and ConverterFactory) are the successors to property editors. Your problem may be that you are not accepting the appropriate type as a parameter to your converter, but that's hard to say without seeing the converter code. If you are expecting Long or Integer you may actually be getting a String from Spring and need to perform that key conversion yourself first.

    As for configuration, I believe you need to list all of your converters in the bean configuration in your xml. If you annotate your converter implementation with @Component you might be able to reference it by the bean name instead of the fully qualified path, but I have only tried that for a ConverterFactory, not a Converter.

    Finally, on specific converters, it looks like you may be able to configure the conversion service at the controller level (see Javi's answer on Setting up a mixed configuration for annotation-based Spring MVC controllers ) and then you could just place that method (and others that require that controller) into a controller that uses a secondary conversion service which you ought to be able to inject by name with the @Resource annotation.

提交回复
热议问题