In spring web mvc application date value is receiv

2019-09-12 16:57发布

I have a spring mvc web application that uses jquery. I used the spring tags to map the fields to pojo's directly. So that the date will get mapped to the corresponding field.

In Spring MVC a feild having date picker is reading date in correct format:

<script type="text/javascript">
    $(document).ready(function () {
        $("#deliveryDate").datepicker({
            minDate: 0
        });
    });

    $(document).ready(function () {
        $("#quoationStartDate").datepicker({
            minDate: 0
        });
    });
</script>

here is the input parameter on JSP:

<div class="col-md-6 col-sm-6">
    <div class="form-group">
        <i class="icon-calendar-7"></i>
        <label>Actual Delivery On</label>   
        <form:input path="deliveryDate" class="form-control required" id="deliveryDate" name="deliveryDate" type="date" placeholder="dd-mm-yyyy" />                 
    </div>
</div>

Have used @Initbinder to parse date

@InitBinder
public void dateBinder(WebDataBinder bind) {
    System.out.println("In Binder");
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-mm-yyyy");
    simpleDateFormat.setLenient(false);
    bind.registerCustomEditor(Date.class, new CustomDateEditor(simpleDateFormat, true));
}

But after a form post operation the date received in the controller has value null. What must be the solution to this so that I will receive a date in format dd-MM-yyyy and this date can be stored into database.

1条回答
Rolldiameter
2楼-- · 2019-09-12 17:22

Works after changing html input type from type="Date" to type="text".

查看更多
登录 后发表回答