Spring 3引入了Converter
SPI,这使得这非常容易。看一下文档中的6.5
从文档中获取资料并放入您的国家/地区,您会做类似的事情
package my.converter;final class StringToCountry implements Converter<String, Country> { public Country convert(String source) { return // whatever you do to get a country from your string }}然后在xml配置中,您将配置转换器
<bean id="conversionService" > <property name="converters"> <list> <bean /> </list> </property></bean>
正如GriffeyDog指出的那样,您可能希望将国家ID放入选择路径,以便可以通过ID或其他方式(而不是Country对象的toString()返回的值)获得Country。


![Spring表格绑定怎么办?无法将类型[java.lang.String]的值转换为必需的类型 Spring表格绑定怎么办?无法将类型[java.lang.String]的值转换为必需的类型](http://www.mshxw.com/aiimages/31/443345.png)
