<!-- 自定义类型格式化转换器配置 -->
<bean id="convertionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="formatters">
<set>
<bean class="com.My.Controller.Fomatter"></bean>
</set>
</property>
</bean>
java代码
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import org.springframework.format.Formatter;
public class Fomatter implements Formatter<Date> {
private String datePattern="yyyy-MM-dd HH:mm:ss";
//声明SimpleDateFormat对象
SimpleDateFormat simpleDateFormat;
@Override
public String print(Date date, Locale locale) {
return new SimpleDateFormat().format(date);
}
@Override
public Date parse(String souce, Locale locale) throws ParseException {
simpleDateFormat = new SimpleDateFormat(datePattern);
return simpleDateFormat.parse(souce);
}
}
扫描二维码,在手机上阅读!
评论