1. Parse the background date type to the front end
1. Add this in the springmvc configuration file. Annotation-driven is only configured once in the configuration file (This method Global effect)
2. Write directly on the field
@JsonFormat(pattern="yyyy-MM-dd",timezone ="GMT-8")
private Date inputtime;
2. Pass the front-end date type to the backend
1. Add this method in the Controller class (This method has global effect)
@InitBinder
public void initBinder(WebDataBinder binder){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
}
2. Add directly to the field
@DateTimeFormat(pattern="yyyy-MM-dd")
private Date beginDate;
The above is the detailed content of Problems that arise when Spring MVC handles dates. For more information, please follow other related articles on the PHP Chinese website!