SpringMVC 提供了一个注解 @DateTimeFormat 。可以将 View 传过来的 String类型转换为 Date 类型。具体使用方式很简单,直接在成员变量上加入注解就可以了,同时还可以指定 format 的格式,如下所示:
import java.util.Date;
import org.springframework.format.annotation.DateTimeFormat;
public class Person {
private String name;
//直接在date类型上加入注解,同时指定格式样式
@DateTimeFormat( pattern = "yyyy-MM-dd" )
private Date birthday;
//setterAndGetter
}
https://www.leftso.com/article/322.html