Struts Flot Double 传0 报错,解决办法

这个错是 XWork 里面的一个 Bug,在 XWork - Version 2.1.3 里面已经解决。管方的 Bug是
[XW-677] - double/float parameters not converted when <= 0

管方的解决方式是 :

Conversion to double/float types does not occur if the value is less than or equal to zero.

This is due to a bug in com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.java in the isInRange method which takes the lower bound of the value to be Double/Float.MIN_VALUE. In fact MIN_VALUE is the smallest positive non-zero number and not the smallest negative number.

Our suggested fix is to negate the value of MAX_VALUE.

 

下面是管网的修改方式,所以介意升级 Xwork 的版本,如果不想升级的话,就把 Xwork 里面的文件按下面这个修改作一下改动。

 

Index: src/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverter.java
===================================================================
--- src/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverter.java	(revision 1925)
+++ src/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverter.java	(working copy)
@@ -428,11 +428,13 @@
         try {
             if (double.class == toType || Double.class == toType) {
                 bigValue = new BigDecimal(stringValue);
-                lowerBound = BigDecimal.valueOf(Double.MIN_VALUE);
+                // Double.MIN_VALUE is the smallest positive non-zero number
+                lowerBound = BigDecimal.valueOf(Double.MAX_VALUE).negate();
                 upperBound = BigDecimal.valueOf(Double.MAX_VALUE);
             } else if (float.class == toType || Float.class == toType) {
                 bigValue = new BigDecimal(stringValue);
-                lowerBound = BigDecimal.valueOf(Float.MIN_VALUE);
+                // Float.MIN_VALUE is the smallest positive non-zero number
+                lowerBound = BigDecimal.valueOf(Float.MAX_VALUE).negate();
                 upperBound = BigDecimal.valueOf(Float.MAX_VALUE);
             } else if (byte.class == toType || Byte.class == toType) {
                 bigValue = new BigInteger(stringValue);

 

用这样的方式,比在 Struts2 上面作过滤要简单的多。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值