前台传递一个时间字符传,后台Spring怎么用Date类型接收?
1)若只是传一个字符传可以在Controller对应的方法参数前加上@DateTimeFormat(pattern = "yyyy-MM-dd" 注解
@RequestMapping(value = "/time",method = RequestMethod.GET)
public String date(@DateTimeFormat(pattern = "yyyy-MM-dd")Date date){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String time = sdf.format(date);
System.out.println(time);
return "success";
}
2)若传递一个拥有Date属性的实体类时,需要在该实体类的对应属性上加上@DateTimeFormat(pattern = "yyyy-MM-dd"注解
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date birthday;
---------------------
作者:激流勇进的少年
来源:CSDN
原文:https://blog.csdn.net/ljw619/article/details/79554281
版权声明:本文为博主原创文章,转载请附上博文链接!

浙公网安备 33010602011771号