在java中,来自cassandra检查的时间戳空值失败

eivnm1vs  于 2021-06-14  发布在  Cassandra
关注(0)|答案(1)|浏览(282)

在我的表单中,我没有选择日期,对于该字段传递为空,而在db中,它被存储为空。在编辑期间,我检查timestamp值为null,而print值为null。但在检查它是否有故障时。
为此,如果条件失败,我将时间戳与null和length==0进行比较。

if(session.getAttribute("deliveryDate").toString()!=null){ 
   String delidate = session.getAttribute("deliveryDate").toString();

     ///////////////date convertion/////////////////
     long unixSecondsfrom = Long.parseLong(delidate); 
      // convert seconds to milliseconds
      Date datefrom = new java.util.Date(unixSecondsfrom); 
      // the format of your date
      SimpleDateFormat sdffrom = new java.text.SimpleDateFormat("yyyy-MM-dd"); 
      String formattedFromDate = sdffrom.format(datefrom);
      ///////////////date convertion/////////////////
      page.set("deliveryDate", formattedFromDate);           

 }else{ page.set("deliveryDate", ""); }

当时间戳为空时,我需要上面的条件为假,它需要转到其他部分。

7xllpg7q

7xllpg7q1#

if语句有一个casting to字符串,在比较之前将对该字符串进行求值,以确定它是否为空值以及双负条件;您可以通过以下方法解决:

if(session.getAttribute("deliveryDate")!=null) { 
    ...

相关问题