1、导入包
<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.3.RELEASE</version>
</dependency>
</dependencies>
2、在Bean中Date类型数据,插入@DateTimeFormat
import org.springframework.format.annotation.DateTimeFormat;
public class User {
private Long id;
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date gmtDate;
@DateTimeFormat(pattern="HHmm")
private Date yesterday;
......
}
3、在Controller控制层接收代码就行了。
@RequestMapping(value="/save",method=RequestMethod.POST)
@ResponseBody
public String save(User user) {
System.out.println(user.getGmtDate());
System.out.println(user.getYesterday());
......
}
4、发送请求
http://localhost:80/save
id=1001&gmtDate=2017-10-22 23:59:59&yesterday=2359