我在这里做错什么,当前请求文件中的xml节点进入,必须填充值01/22/2020。测试人员正在运行新的测试用例,而不是在填充并且抛出异常。我该如何接受空字符串。
ParseException:无法解析的日期:“”。
在java.text.DateFormat.parse
public static Date convertStringtoDate(String stringDate, String format) throws ParseException{
if(stringDate!=null){
if(stringDate.contains("-")){
format = "yyyy-MM-dd";
}else if (stringDate.contains("/")){
format = "MM/dd/yyyy";
}
SimpleDateFormat formatter = new SimpleDateFormat(format);
return formatter.parse(stringDate);
}else{
return null
}
}
}
代替if(stringDate!= null)使用StringUtils.isEmpty()