double为0或0.0时异常
?
版本:struts2.1.6
发生:页面传递double类型变量
解决方法:
添加转换器DoubleConvert
?
package com;import java.util.Map; import org.apache.struts2.util.StrutsTypeConverter; public class DoubleConvert extends StrutsTypeConverter { @SuppressWarnings("unchecked")@Override public Object convertFromString(Map context, String[] values, Class toClass) { if (Double.class == toClass) { String doubleStr = values[0]; Double d = Double.parseDouble(doubleStr); return d; } return 0; } @SuppressWarnings("unchecked")@Override public String convertToString(Map context, Object o) { return o.toString(); } }?
新建配置文件xwork-conversion.properties到src
添加内容:
java.lang.Double=com.DoubleConvert