大牛们,我昨晚已经在提问区提问了。。。但是没解决,白天再来问一下,就是我前端用的datetime-local来设置时间,但是在后台获取的时候,却为null,时间属性我也有加上注解,通过对象中其他属性都能正常获取,请问该怎么解决?
####前端
<div class="form-group">
<label class="col-sm-3 control-label">培训开始时间:</label>
<div class="col-sm-8">
<input id="trainStarttime" name="trainStarttime" th:field="*{trainStarttime}" class="form-control" type="datetime-local" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">培训结束时间:</label>
<div class="col-sm-8">
<input id="trainEndtime" name="trainEndtime" th:field="*{trainEndtime}" class="form-control" type="datetime-local" required>
</div>
</div>
####bean类
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date trainStarttime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date trainEndtime;
对应的getter和setter方法
public String getTrainPlace()
{
return trainPlace;
}
public void setTrainStarttime(Date trainStarttime)
{
this.trainStarttime = trainStarttime;
}
public Date getTrainStarttime()
{
return trainStarttime;
}
public void setTrainEndtime(Date trainEndtime)
{
this.trainEndtime = trainEndtime;
}
public Date getTrainEndtime()
{
return trainEndtime;
}
####后台
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(TrainApplication trainApplication)
{
System.out.println("!@#"+trainApplication);
return toAjax(trainApplicationService.insertTrainApplication(trainApplication));
}
获取的内容:
trainName=123
trainTarget=312
trainForm=312
trainTutor=321
trainPlace=312
trainStarttime=<null>
trainEndtime=<null>