问题描述:在做一个Excel文件导入导出的功能时,Excel的一个日期的字段是空值,而我对应的java  bean 对应的属性是一个date类型,直接赋值会报错

解决方法(待改进):

我在set进java bean之前进行了判断看传过来的数据是不是空值

String finepaydate = "";                             
String finepaydate1 = "";
finepaydate1 = cell.getStringCellValue().trim();
if(!StringUtils.isBlank(finepaydate1)){
    finepaydate = finepaydate1;
}else{
    finepaydate = null;
if(!StringUtils.isBlank(finepaydate)){//判断为否为空
    hBaseCbljlc.setFinepaydate(simpleDateFormat.parse(finepaydate));

小节:我在网上看了一些其他的文章,不能直接赋值的原因是因为""属于String类型不符合Date的期望类型,会报错,不过null却可以直接赋值Date  以后会尝试下判断是否为空值然后直接赋值null (项目已经提交 不想改啦  哈哈哈哈)

Key Features Your entry ticket to the world of data science with the stability and power of Java Explore, analyse, and visualize your data effectively using easy-to-follow examples Make your Java applications more capable using machine learning Book Description Data science is concerned with extracting knowledge and insights from a wide variety of data sources to analyse patterns or predict future behaviour. It draws from a wide array of disciplines including statistics, computer science, mathematics, machine learning, and data mining. In this book, we cover the important data science concepts and how they are supported by Java, as well as the often statistically challenging techniques, to provide you with an understanding of their purpose and application. The book starts with an introduction of data science, followed by the basic data science tasks of data collection, data cleaning, data analysis, and data visualization. This is followed by a discussion of statistical techniques and more advanced topics including machine learning, neural networks, and deep learning. The next section examines the major categories of data analysis including text, visual, and audio data, followed by a discussion of resources that support parallel implementation. The final chapter illustrates an in-depth data science problem and provides a comprehensive, Java-based solution. Due to the nature of the topic, simple examples of techniques are presented early followed by a more detailed treatment later in the book. This permits a more natural introduction to the techniques and concepts presented in the book. What you will learn Understand the nature and key concepts used in the field of data science Grasp how data is collected, cleaned, and processed Become comfortable with key data analysis techniques See specialized analysis techniques centered on machine learning Master the effective visualization of your data Work with the Java APIs and techniques used to perform data analysis 遇到个问题,记录一下,从controller层到数据库都是date类型的字段,已有数据,更新为null,用的是非更新,不能直接改成null就更新,可能会影响其他业务,最后使用了以下方案,要是有更好的方案,欢迎留言! public static String getTimeShort() { SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); Date currentTime = new Date(); String dateString = formatter.format(currentTime); return dateString; * 将长时间格式字符串转换为时间 yyyy-MM-dd HH:mm:ss * @param strDate * @return public static Date strToDateLong(String strDate) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); ParsePosition pos = new ParsePosition(0); Date strtodate = formatter.parse(strDate, pos); return strtodate; * 将长时间格式时间转换为字符串 yyyy-MM-dd HH:mm:ss * @param dateDate * @return public static String dateToStrLong(java.util.Date dateDate) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateString = formatter.format(dateDate); return dateString; * 将短时间格式时间转换为字符串 yyyy-MM-dd * @param dateDate * @param k * @return public static String dateToStr(java.util.Date dateDate) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); String dateString = formatter.format(dateDate); return dateString; * 将短时间格式字符串转换为时间 yyyy-MM-dd * @param strDate * @return public static Date strToDate(String strDate) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); ParsePosition pos = new ParsePosition(0); Date strtodate = formatter.parse(strDate, pos); return strtodate; * 得到现在时间 * @return public static Date getNow() { Date currentTime = new Date(); return currentTime; * 提取一个月的最后一天 * @param day * @return public static Date getLastDate(long day) { Date date = new Date(); long date_3_hm = date.getTime() - 3600000 * 34 * day; Date date_3_hm_date = new Date(date_3_hm); return date_3_hm_date; Javajava.util.Date类是Java初的时间类之一。该类的大部分方法已不推荐使用,取而代之的是java.util.Calendar类。不过你仍然可以使用java.util.Date类去表示某个时间。下面是一个如何实例化java.util.Date的例子:   java.util.Date date = new java.util.Date();   Date实例包含了当前时间作为它的日期和时间。   你可以通过getTime()方法访问java.util.Date实例的日期和时间,比如像这样:   java.util.Date date = new java.util.D I need your help in initializing a java.util.Date variable to empty. As I am running the page and it is showing nullpointerexception if I didn't select any date.The code is:private java.util.Date date... (1) SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd"); (2) Date date = dateformat.parse("2016-6-19"); (3) System.out.println(dateformat.format(date)); 来源:Java 实现日期 Date赋值_梓鸿-CSDN博客_date赋值 最近遇到SpringMVC写个controller类,传一个串的字符类型过来,正常情况是会自动转成date类型的,因为数据表对应类类型就是date的解决方法是在controller类的后面加个注解:@InitBinderprotected void initDateFormatBinder(WebDataBinder binder) {SimpleDateFormat dateFormat = ... private String strDate;//前端接收这个 private Date date; //如果strDate不为在实体类里将strDate转成date 为了方便项目开发我们往往就是会使用到一下帮助类来简化我们项目开发的繁琐工作       下面介绍一种我在一些项目使用到的一个工具类PageData的使用,可以满足项目大部分数据传递存储使用作用                详细直接上代码 日期字段导致保存异常数据库端表结构可以看到字段 bill_datedatetime 日期类型,没有设置为 not null,那么如果前段传递来的对象该属性为,应该可以保存。HTTP请求测试代码测试代码如下:@Testpublic void test01() throws Exception {RawMain record = new RawMain();record.setBill_t... <br />org.apache.commons.beanutils.ConversionException: No value specified for 'Date'<br />现在系统里原先不出错的地方老是出现以上这个错误,不知道什么原因。也都是BeanUtils.copyProperties(teaInfo, infoForm);这种语句出的错。 <br />今天查了一上午,找到了它的用法,原来它是一种反射机制,使用copyProperties可以复制bean,不必重复写很多属性,只是效率不高。 <