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

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.

主站蜘蛛池模板: 邻水| 吴桥县| 湖南省| 花垣县| 余干县| 化德县| 石棉县| 昌邑市| 辛集市| 武乡县| 宜春市| 彭阳县| 霍林郭勒市| 天气| 赫章县| 吉林省| 长宁区| 平远县| 陕西省| 和政县| 江阴市| 彩票| 湖州市| 淮滨县| 自贡市| 射洪县| 吉水县| 昌江| 正镶白旗| 南京市| 大宁县| 千阳县| 南城县| 宝丰县| 万荣县| 沾益县| 林西县| 合江县| 左云县| 洪雅县| 来安县|