Spring boot serves as a simple service architecture for microservices. has its own characteristics. Quick and easy to build architecture. Here I'm simply introducing two of the issues I've met. The time type passed by the first foreground page cannot be automatically mapped to the Java Date type issue.
A spring container registers the mapping into the container when it is launched. Takes effect as the container starts. Sometimes it's missing the mapping we need, so we need to add a bean to our container to do our own mapping. Details are handled as follows.
@Bean
Public converter<string, Date> Addnewconvert () {
return new converter<string, date> () {
@Override
Public Date convert (String source) {
SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd");
Date date = null;
try {
Date = Sdf.parse ((String) source);
} catch (ParseException e) {
E.printstacktrace ();
}
return date;
}
};
}
Two. We found a 8-hour time difference when using this architecture. It's also a matter of architecture.
Solution Add Spring.jackson.time-zone=gmt+8 in the Application.properties file
If the time data returned from the controller needs to be directly into a fixed string format, you need to add the following configuration in Application.properties
SPRING.JACKSON.DATE-FORMAT=YYYY-MM-DD HH:mm:ss
Let the configuration file load into the spring container when it is started.
Spring Boot Date Conversion