我是 Spring MVC 的新手 - 我正在尝试将我的 javascript 中的日期作为请求参数传递
我的 Controller 看起来像 -
public @ResponseBody List<RecordDisplay> getRecords(
@RequestParam(value="userID") Long userID,
@RequestParam(value="fromDate") Date fromDate,
@RequestParam(value="toDate") Date toDate) {
我的问题是如何从 javascript 进行调用 - 就像 URL 的样子
for eg. - /getRecords?userID=1&fromDate=06022013&toDate=08022013'
我是否需要一种方法来解析日期以便 Spring 能够识别它?
最佳答案
使用 @DateTimeFormat("MMddyyyy")
public @ResponseBody List<RecordDisplay> getRecords(
@RequestParam(value="userID") Long userID,
@RequestParam(value="fromDate") @DateTimeFormat(pattern="MMddyyyy") Date fromDate,
@RequestParam(value="toDate") @DateTimeFormat(pattern="MMddyyyy") Date toDate) {
关于java - 在 Spring MVC 中传递日期以请求参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14766818/