在Spring MVC中传递日期以请求参数 [英] Passing date to request param in Spring MVC

查看:121
本文介绍了在Spring MVC中传递日期以请求参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Spring MVC的新手-我正在尝试将JavaScript中的日期作为请求参数传递给

I am new to Spring MVC - and I am trying to pass a date from my javascript as a request Param

我的控制器看起来像-

public @ResponseBody List<RecordDisplay> getRecords(
            @RequestParam(value="userID") Long userID,
            @RequestParam(value="fromDate") Date fromDate,
            @RequestParam(value="toDate") Date toDate) {

我的问题是如何通过javascript拨打电话-网址应为

The question I have is how do I make the call from javascript - as in what should the URL look like

for eg. - /getRecords?userID=1&fromDate=06022013&toDate=08022013'

我需要一种解析日期的方法,以便Spring可以识别它吗?

Do I need a way to parse the date so Spring can recognize it?

推荐答案

使用@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) {

这篇关于在Spring MVC中传递日期以请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆