1. 如果要dto 上不显示 null 值的直段那么使用注解
@Data @JsonInclude(JsonInclude.Include.NON_NULL) public class OrderDTO { //todo }
2. 配置全局的设置可以在yml 配置文件
spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver username: root password: url: jdbc:mysql://localhost:3306/sell?serverTimezone=GMT%2B8&characterEncoding=utf-8&userSSL=false jpa: show-sql: true jackson: default-property-inclusion: non_null
3.要字段必须返回
public class OrderDTO { private String orderId; private String buyerName; private String buyerPhone = ""; }