taitoushan 2009-10-15 14:55
浏览 269
已采纳

为啥判断出来不为null而输出的结果却是null呢?

[code="java"][/code][code="java"]System.out.println("common中的date1:"+fileForm.getDate1());
System.out.println("common中的date2:"+fileForm.getDate2());
System.out.println("fileForm.getDate1() != null的值:"+(fileForm.getDate1() != null));
System.out.println("fileForm.getDate2() != null的值:"+(fileForm.getDate2() != null));
System.out.println("common中的date2的值:"+fileForm.getDate2());
try {
spx = new SqlParameterExt();
if (fileForm.getDate1() != null && !"".equals(fileForm.getDate1())) {
System.out.println("第一个时间不为空");
if (fileForm.getDate2() != null && !"".equals(fileForm.getDate2())) {
System.out.println("第一个时间不为空,第二个时间也不为空");
// 前后时间都不为空
// Sybase数据库中,查询时间区间时,不包括后面的时间点,
// 因此查询时,将后面的时间点多加一天 (60*60*24*1000一天的毫秒数)
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd");
long lo = dateFormat.parse(fileForm.getDate2()).getTime();
lo = lo + 60 * 60 * 24 * 1000;
Date d = new Date(lo);
String Date2 = dateFormat.format(d);
sql = sql + " where a.tqrq between '" + fileForm.getDate1()
+ "' and '" + Date2 + "' ";
System.out.println("第一个时间不为空,第二个时间也不为空");

            } else{
                System.out.println("第一个时间不为空,第二个时间为空");
                // 后时间为空
                // Sybase数据库中,查询时间区间时,不包括后面的时间点,
                // 因此查询时,将后面的时间点多加一天 (60*60*24*1000一天的毫秒数)
                SimpleDateFormat dateFormat = new SimpleDateFormat(
                        "yyyy-MM-dd");
                long lo = dateFormat.parse(DateUtils.getCurDate())
                        .getTime();
                lo = lo + 60 * 60 * 24;
                Date d = new Date(lo);
                String Date2 = dateFormat.format(d);

                sql = sql + " where a.tqrq between '" + fileForm.getDate1()
                        + "' and '" + Date2 + "' ";
            }
        }
        //sql = sql + " order by a.tqbh desc";

    } catch (Exception err) {
        // throw new CallDbException("参数不合法!" + err.getMessage());
        System.out.println(err.getMessage());
    }
    sql = sql + " order by a.tqbh desc";[/code]

输出结果很让人纳闷

中间有两句
[code="java"]System.out.println("fileForm.getDate2() != null的值:"+(fileForm.getDate2() != null));
System.out.println("common中的date2的值:"+fileForm.getDate2());[/code]

输出结果很怎么会是这样的?
[color=red]fileForm.getDate2() != null的值:true
common中的date2的值:null[/color]

  • 写回答

8条回答 默认 最新

  • wanghaolovezlq 2009-10-15 15:11
    关注

    那就说明fileForm.getDate2()这个对象是不等于null的

    但是fileForm.getDate2().toString()等于null

    有个点你没搞清楚,
    用System.out.println("common中的date2的值:"+fileForm.getDate2()); 方式打印对象是会调用这个对象的toString()方法

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(7条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line