User user = new User();
user.setUsername(request.getParameter("username"));
user.setPassword(request.getParameter("password"));
user.setAge(Integer.parseInt(request.getParameter("age")));
user.setAddress(request.getParameter("address"));
user.setSalary(Double.parseDouble(request.getParameter("salary")));
.....
org.apache.commons.beanutils.ConversionException: DateConverter does not support default String to 'Date' conversion.
org.apache.commons.beanutils.converters.DateTimeConverter.toDate(DateTimeConverter.java:468)
org.apache.commons.beanutils.converters.DateTimeConverter.convertToType(DateTimeConverter.java:343)
org.apache.commons.beanutils.converters.AbstractConverter.convert(AbstractConverter.java:156)
.....
面对这种情况,就需要注册一个转换器来应对:
User user = new User();
ConvertUtils.register(new Converter() {
@Override
public Object convert(Class aClass, Object o) {
// 如果字符串为null,则返回null
if(o == null)
return null;