Java Spring @RequestParam 日期格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29657086/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 08:22:47 来源:igfitidea点击:
Spring @RequestParam Date Formatting
提问by
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
.
您如何@RequestParam
使用注释格式化传入的内容?表单以 MM/DD/YYYY 格式发送日期,控制器未将其作为有效的Date
.
@RequestMapping(params="/updateDate")
public @ResponseBody String updateDate(HttpServletRequest request
, @RequestParam Integer productId
, @RequestParam Date dateReceived) {
// Code here...
}
采纳答案by Shaggy
Use the Spring annotation DateTimeFormat
使用 Spring 注解DateTimeFormat
@RequestMapping(params="/updateDate")
public @ResponseBody String updateDate(HttpServletRequest request
, @RequestParam Integer productId
, @RequestParam @DateTimeFormat(pattern="MM/dd/yyyy") Date dateReceived) {
// Code here...
}