对于实际开发中,我们的统一返回dto,也有可能要求不同情况返回不同的字段,比如下面的返回dto:
package com.walletServer.dto;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonView;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Description: BaseResponseDto
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class BaseResponseDto implements Serializable {
private static final long serialVersionUID = 2120869894112984147L;
public interface SuccessView {
};
public interface ErrorView extends SuccessView {
};
@JsonView(BaseResponseDto.SuccessView.class)
private long id;
@JsonView(BaseResponseDto.SuccessView.class)
private Object data;
@JsonView(BaseResponseDto.ErrorView.class)
private String error;
public static BaseResponseDto Ok(Object da