qq_35156026
2019-04-25 15:21
采纳率: 40%
浏览 1.7k
已采纳

datetime-local获取的值为null,急急急!

大牛们,我昨晚已经在提问区提问了。。。但是没解决,白天再来问一下,就是我前端用的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>
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • 像忘了谁sq 2019-04-25 16:01
    已采纳

    页面表单

    <input id="wbTime" name="wbTime" class="form-control" type="datetime-local" >
    

    页面赋值

    $(document).ready(function(){
        var t = "${asset.wbTime!,'yyyy-MM-dd HH:mm'}";
        t = t.substring(0,10)+'T'+t.substring(11,16);
        $("#wbTime").val(t);
    })
    

    实体类

    public Date getWbTime() {
            return wbTime;
        }
    
        public void setWbTime(Date wbTime) {
            this.wbTime = wbTime;
        }
    
    打赏 评论

相关推荐 更多相似问题