官术网_书友最值得收藏!

Configuring custom PropertyEditors

In the previous example, we learned how to configure converters for an HTTP request and response data. There are other kinds of conversions that take place, especially in regards to dynamically converting parameters to various objects, such as Strings to Date or an Integer.

When we declare a mapping method in a controller, Spring allows us to freely define the method signature with the exact object types that we require. The way in which this is achieved is via the use of the PropertyEditor implementations. PropertyEditor is a default concept defined as part of the JDK and designed to allow the transformation of a textual value to a given type. It was initially intended to be used to build Java Swing / Abstract Window Toolkit (AWT) GUI and later proved to be a good fit for Spring's need to convert web parameters to method argument types.

Spring MVC already provides you with a lot of PropertyEditor implementations for most of the common types, such as Boolean, Currency, and Class. Let's say that we want to create a proper Isbn class object and use this in our controller instead of a plain String.

主站蜘蛛池模板: 长汀县| 龙江县| 固原市| 高青县| 永清县| 孟州市| 皮山县| 固安县| 盘山县| 来安县| 永昌县| 偏关县| 无极县| 门头沟区| 津南区| 亚东县| 绍兴县| 广灵县| 吴桥县| 日土县| 龙井市| 德令哈市| 改则县| 界首市| 云南省| 东台市| 汉寿县| 遵化市| 睢宁县| 卫辉市| 东方市| 洪江市| 渝中区| 安丘市| 北票市| 台中市| 赤水市| 资溪县| 乐安县| 元朗区| 惠水县|