带有Spring MVC的jQuery datepicker - 将日期从视图传递到控制器会发送null [英] jQuery datepicker with Spring MVC - Passing date from view to controller sends null
问题描述
提交表单后,我看到所有值正确传递给控制器,除了传递为null的日期(表单中的日期选择在输入字段中输入正确的日期)我尝试添加但是它没有帮助。我也尝试删除路径并将其替换为中的name,但它会抛出错误,说path属性丢失。我试过跟随但没有运气 -
1. 在弹簧web mvc应用程序日期值在jsp页面上从日期选择器读取后在控制器中被接收为NULL
2. http://blog.teamextension.com/date-binding-in-spring-mvc -1321
After submitting the form , I see all the values being passed properly to the controller except date which is passed as null(The date selection in the form enters a proper date in the input field) I tried adding but it did not help. I also tried removing "path" and replacing it with "name" in the "" but it throws error saying "path" attribute is missing. I tried following but no luck-
1. In spring web mvc application date value is received as NULL in controller after reading from date-picker on jsp page
2. http://blog.teamextension.com/date-binding-in-spring-mvc-1321
jQuery:
$(document).ready(function(){
$( #datepicker)。datepicker({dateFormat:yy-mm-dd});
});
JSP:
<div class="plLabelSearch" id="hiddenField">Due Date:</div>
<div class="plinput"><form:input type="text" id="datepicker" path="dueDate" placeholder="yyyy-mm-dd"/></div>
型号:
@Column(name = "DUE_DATE")
@DateTimeFormat(pattern = "yyyy/mm/dd")
private Date dueDate;
控制器:
@RequestMapping(value="/lock", method = RequestMethod.POST)
public @ResponseBody Status lockDevice(@ModelAttribute("adminTransaction") @Validated AdminTransaction adminTransaction, BindingResult result, Model model, Locale locale,Map<String, Object> map, HttpServletRequest request) {
try {
/*.......CODE.........*/
adminTransactionDO.setDueDate(adminTransaction.getDueDate());
/*.......CODE.........*/
}
return new Status("success", "Transaction inserted Successfully !");
} catch (Exception e) {
return new Status("error", e.toString());
}
}
推荐答案
它看起来像你的:
@Column(name = "DUE_DATE")
@DateTimeFormat(pattern = "yyyy/mm/dd")
private Date dueDate;
问题是什么。 Spring无法将其转换为日期。
Is the problem. Spring is unable to convert it into Date.
请尝试
private String dueDate;
这篇关于带有Spring MVC的jQuery datepicker - 将日期从视图传递到控制器会发送null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!