Springboot reception return time using LocalDateTime

1. a reference

@Data
@ApiModel
public class ResVO {
	@JsonFormat(pattern="yyyy-MM-dd HH",shape=JsonFormat.Shape.STRING)
	@ApiModelProperty(name="dateTime",value="日期",example="2020-03-17 12:07:00")
	private LocalDateTime dateTime;
}

2. the parameters
a.Date type

@Data
@ApiModel(description="入参对象",value="rucna")
public class ReqVO {
	@JsonFormat(pattern="yyyy-MM-dd")
	@ApiModelProperty(name="dateTime",required=true,example="2020-12-10")
	private Date dateTime;
}

b.LocalDateTime type

public class DateDeserializer extends JsonDeserializer<LocalDateTime> {

    @Override
    public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    	if (StringUtils.isBlank(jsonParser.getText()))
            return null;
        LocalDate localDate = LocalDate.parse(jsonParser.getText(), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        return LocalDateTime.of(localDate, LocalTime.MIN);
    }
}
@Data
@ApiModel(description="入参对象",value="rucna")
public class ReqVO {
	@JsonDeserialize(using = DateDeserializer.class)
	@ApiModelProperty(name="dateTime",required=true,example="2020-12-10")
	private LocalDateTime dateTime;
}

3. the reference
Here Insert Picture Description
4. The content of the reference
Here Insert Picture Description

Published 47 original articles · won praise 5 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_37460672/article/details/104918814