Method Parameters And Type Conversion

来源:互联网 发布:焊缝作图软件 编辑:程序博客网 时间:2024/05/29 01:55
String-based values extracted from the request including request parameters, path variables, request headers, and cookie values may need to be converted to the target type of the method parameter or field (e.g., binding a request parameter to a field in an @ModelAttribute parameter) they’re bound

to. If the target type is not String, Spring automatically converts to the appropriate type. All simple types such as int, long, Date, etc. are supported. You can further customize the conversion process through a WebDataBinder (see the section called “Customizing WebDataBinder initialization”) or by registering Formatters with the FormattingConversionService (see Section 8.6, “Spring Field Formatting”).


8.5 Spring Type Conversion
Spring 3 introduces a core.convert package that provides a general type conversion system. The
system defines an SPI to implement type conversion logic, as well as an API to execute type conversions
at runtime. Within a Spring container, this system can be used as an alternative to PropertyEditors to
convert externalized bean property value strings to required property types. The public API may also be
used anywhere in your application where type conversion is needed.

0 0
原创粉丝点击