1、实体类属性加注解,Integer时间转时间戳,用于前端展示
@Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.METHOD}) @JacksonAnnotationsInside @JsonSerialize(using = JsonIntDateFormatSerializer.class) public @interface JsonIntDateFormat { } public class JsonIntDateFormatSerializer extends JsonSerializer<Integer> { @Override public void serialize(Integer date, JsonGenerator gen, SerializerProvider serializers) throws IOException { if(null!=date){ DateTime dateTime = new DateTime(date * 1000L); gen.writeString(dateTime.toString("yyyy-MM-dd HH:mm:ss")); }else { gen.writeString(""); } } } public class SecurityOpExceptionInfo{ private String uuid;// uuid @JsonIntDateFormat private Integer loginTime;// 登录时间 }