Spring Date Formatting @RequestParam

How to format an inbox @RequestParamusing annotations? The form sends the date in the format MM / DD / YYYY, and the controller does not select it as valid Date.

@RequestMapping(params="/updateDate")
public @ResponseBody String updateDate(HttpServletRequest request
        , @RequestParam Integer productId
        , @RequestParam Date dateReceived) {
    // Code here...
}
+2
source share
1 answer

Use Spring DateTimeFormat annotation

@RequestMapping(params="/updateDate")
public @ResponseBody String updateDate(HttpServletRequest request
        , @RequestParam Integer productId
        , @RequestParam @DateTimeFormat(pattern="MM/dd/yyyy") Date dateReceived) {
    // Code here...
}
+7
source

All Articles