你需要使用
java.sql.Date
而不是
java.time.LocalDate
。如果你想了解映射关系,请查看
springfox.documentation.schema.Types
。下面是完整的示例:
@JsonFormat(pattern="yyyy-MM-dd")
@ApiModelProperty(dataType = "java.sql.Date")
private Date birthDate;
最初的回答
将生成以下内容:
properties: {
birthDate: {
type: "string",
format: "date"
}
}
以下是与 springfox.documentation.schema.Types
相关的内容:
最初的回答:
private static final Map<Type, String> typeNameLookup = ImmutableMap.<Type, String>builder()
.put(Long.TYPE, "long")
.put(Short.TYPE, "int")
.put(Integer.TYPE, "int")
.put(Double.TYPE, "double")
.put(Float.TYPE, "float")
.put(Byte.TYPE, "byte")
.put(Boolean.TYPE, "boolean")
.put(Character.TYPE, "string")
.put(Date.class, "date-time")
.put(java.sql.Date.class, "date")
.put(String.class, "string")
.put(Object.class, "object")
.put(Long.class, "long")
.put(Integer.class, "int")
.put(Short.class, "int")
.put(Double.class, "double")
.put(Float.class, "float")
.put(Boolean.class, "boolean")
.put(Byte.class, "byte")
.put(BigDecimal.class, "bigdecimal")
.put(BigInteger.class, "biginteger")
.put(Currency.class, "string")
.put(UUID.class, "uuid")
.put(MultipartFile.class, "__file")
.build();
java.sql.Date
类型不应该在 REST API 中暴露的 DTO 中泄漏。 - Marc Bouvier