post方式时间格式统一
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import java.io.IOException;
public class MultiFormatDateTimeDeserializer extends JsonDeserializer
@Overridepublic String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {String text = p.getText().trim();// 补全时间if (text.matches("^\\d{4}-\\d{2}$")) { // yyyy-MMtext += "-01 00:00:00";} else if (text.matches("^\\d{4}-\\d{2}-\\d{2}$")) { // yyyy-MM-ddtext += " 00:00:00";} else if (text.matches("^\\d{4}-\\d{2}-\\d{2} \\d{2}$")) { // yyyy-MM-dd HHtext += ":00:00";} else if (text.matches("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}$")) { // yyyy-MM-dd HH:mmtext += ":00";}//DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");return text;}
}
字段添加注解
@JsonDeserialize(using = MultiFormatDateTimeDeserializer.class)
转载请注明作者和出处,并添加本页链接。
原文链接:
//pongpongkai.top/63
沪公网安备31011202021249号