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

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.

主站蜘蛛池模板: 西安市| 尼玛县| 玉树县| 桦南县| 南和县| 罗江县| 南昌县| 承德县| 利辛县| 宝山区| 洪江市| 肥西县| 阳原县| 伊川县| 镇巴县| 高密市| 隆尧县| 衡南县| 德江县| 桃园市| 休宁县| 九江县| 麻江县| 昭苏县| 陵川县| 含山县| 家居| 镇巴县| 石渠县| 平潭县| 无为县| 沙河市| 安顺市| 开封县| 宝坻区| 拜城县| 昭通市| 泾阳县| 揭东县| 阜阳市| 平原县|