Step 1: Create the CustomObjectMapper class
/*** Solve the problem that the date format is displayed as a timestamp by default when spring MVC returns json using @ ResponseBody. Cooperation required
Use ** @ author hellostory * @ date 2013-10-31 04:17:52 */@ Component ("plugin") public class extends ObjectMapper {public customObjectMapper () {CustomSerializerFactory factory = new CustomSerializerFactory (); factory. addGenericMapping (Date. class, new JsonSerializer
() {@ Overridepublic void serialize (Date value, JsonGenerator jsonGenerator, SerializerProvider) throws IOException, JsonProcessingException {SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss "); jsonGenerator. writeString (sdf. format (value) ;}}); this. setSerializerFactory (factory );}}
Step 2: Configure as follows:
The effect is as follows:
Before formatting:
After formatting: