Spring @RequestParam Date Formatting [duplicate]

2019-07-01 17:51发布

This question already has an answer here:

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...
}

1条回答
别忘想泡老子
2楼-- · 2019-07-01 18:37

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...
}
查看更多
登录 后发表回答