Spring @RequestParam Date Formatting [duplicate]
Asked Answered
P

1

10

How do you format the incoming @RequestParam using annotations? The form is sending the date in MM/DD/YYYY format and the controller is not picking it up as a valid Date.

@RequestMapping(params="/updateDate")
public @ResponseBody String updateDate(HttpServletRequest request
        , @RequestParam Integer productId
        , @RequestParam Date dateReceived) {
    // Code here...
}
Psi answered 15/4, 2015 at 17:40 Comment(0)
R
30

Use the Spring annotation DateTimeFormat

@RequestMapping(params="/updateDate")
public @ResponseBody String updateDate(HttpServletRequest request
        , @RequestParam Integer productId
        , @RequestParam @DateTimeFormat(pattern="MM/dd/yyyy") Date dateReceived) {
    // Code here...
}
Ramiah answered 15/4, 2015 at 17:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.