spring数据绑定默认的日期解析格式解析不了yyyy格式

当日期格式是yyyy-MM或者yyyy-MM-dd,都可以通过对象传到后台但就是yyyy格式传不过去,最后的处理办法:

String currentTime = request.getParameter("currentTime");

这样就可以在后台接受。

作为前台查询条件,查询之后前台还要回显,我只这样处理的:

//其实前台只需要年,后面的月和日并不重要,只是为了能够让spring解析传到前台

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String currentTimea = currentTime.concat("-01-01");
Date currentT = dateFormat.parse(currentTimea);
log.setCurrentTime(currentT);
//下面为前台日期
<label>年份:</label>
<input id="currentTime" name="currentTime" type="text" readonly="readonly" maxlength="20" class="input-mini Wdate"
value="<fmt:formatDate value="${log.currentTime}" pattern="yyyy"/>" onclick="WdatePicker({dateFmt:'yyyy',isShowClear:true});"/>
原文地址:https://www.cnblogs.com/person008/p/9032127.html