當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
SpringMvc接收日期参数
生活随笔
收集整理的這篇文章主要介紹了
SpringMvc接收日期参数
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
首先引入jodatime jar
<dependency><groupId>joda-time</groupId><artifactId>joda-time</artifactId><version>2.9.9</version> </dependency>Controller方法通過@DateTimeFormat注解來接收參數(shù)
@RequestParam("time")?@DateTimeFormat(pattern =?"yyyy-MM-dd HH:mm:ss") Date time傳入值?time=2017-12-12
也可通過實體接收
@InitBinder("query") public void initBinderQuery(WebDataBinder binder) {SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");dateFormat.setLenient(false);binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));binder.setFieldDefaultPrefix("query."); }傳入值?query.time=2017-12-12
總結(jié)
以上是生活随笔為你收集整理的SpringMvc接收日期参数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java配置信息工具jinfo
- 下一篇: 使用itextpdf操作pdf