1. 程式人生 > >SpringMVC 配置 自定義資料型別轉換

SpringMVC 配置 自定義資料型別轉換

import org.springframework.core.convert.converter.Converter;

public class StringToDouble implements Converter<String, Double>{

	@Override
	public Double convert(String source) {
		if (source.isEmpty()) {
			return 0.0;
		}
		else {
			return Double.parseDouble(source);
		}
	}
}
<mvc:annotation-driven conversion-service="conversionService"></mvc:annotation-driven>
	<bean id="conversionService"
		class="org.springframework.context.support.ConversionServiceFactoryBean">
		<property name="converters">
			<list>
				<bean class="com.thinkgem.jeesite.common.config.StringToDouble" />
			</list>
		</property>
	</bean>