为啥判断出来不为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]

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

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

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

会不会是 fileForm.getDate2() 返回字符串的 "null" ?

null 和 “” 是不同的 你只判断了 null 没有判断 “”

判断fileForm.getDate2().equal("")的情况

[code="java"]System.out.println("fileForm.getDate2() != null的值:"+(fileForm.getDate2() != null));
System.out.println("fileForm.getDate2() 不为null字符:"+(fileForm.getDate2().equal("null")));

System.out.println("common中的date2的值:"+fileForm.getDate2());[/code]

你的data2中的值是字符串"null"吧。

同意rickqin 的想法.

debug一下fileForm中date2属性的toString()方法。

因为输出的是字符串"null" :lol: :lol: :lol: