Spring @RequestParam 日期格式

Spring @RequestParam Date Formatting

如何使用注释格式化传入的 @RequestParam?表单以 MM/DD/YYYY 格式发送日期,控制器未将其作为有效的 Date.

选择
@RequestMapping(params="/updateDate")
public @ResponseBody String updateDate(HttpServletRequest request
        , @RequestParam Integer productId
        , @RequestParam Date dateReceived) {
    // Code here...
}

使用Spring注解DateTimeFormat

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