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

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.

主站蜘蛛池模板: 长顺县| 当阳市| 乐陵市| 南充市| 保靖县| 澄江县| 新密市| 隆尧县| 富宁县| 襄城县| 离岛区| 彭泽县| 商洛市| 抚顺市| 儋州市| 柳河县| 鹿邑县| 饶河县| 泌阳县| 兴隆县| 门头沟区| 蓬安县| 思南县| 福海县| 云和县| 旬邑县| 保德县| 井陉县| 藁城市| 庆阳市| 手机| 彭州市| 宝应县| 榕江县| 中江县| 钟祥市| 水城县| 天峨县| 射洪县| 普宁市| 巴彦淖尔市|