Spring @RequestParam Date Formatting [duplicate]

醉酒当歌 提交于 2019-12-10 15:26:13

问题


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:


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


来源:https://stackoverflow.com/questions/29657086/spring-requestparam-date-formatting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!