Home >Java >javaTutorial >Problems that arise when Spring MVC handles dates

Problems that arise when Spring MVC handles dates

零下一度
零下一度Original
2017-06-25 10:25:511399browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn