VO,DTO,DO如何使用

VO,DTO,DO如何使用

前端传回一个对象,用VO接收,用DTO传给后端

@PostMapping("/newInterview")
public ResultWrapper addNewComment(@RequestBody InterviewNewCommentVO comment) {
    comment.setInterviewerId(getMyId());
    logger.info(comment.toString());
    interviewService.addNewCommentSyn(comment.toInterviewCommentDTO());
    return new ResultWrapper();
}

VO

@Data
@NoArgsConstructor
public class InterviewCommentVO {
    private Integer interviewId;
    private String interviewerId;
    private Boolean result;
    private String comment;
    private String interviewerName;
    private String departmentName;
    private Boolean isParticipated;

    public InterviewCommentDTO toInterviewCommentDTO() {
        InterviewCommentDTO dto = new InterviewCommentDTO();
        dto.setInterviewId(interviewId);
        dto.setInterviewerId(interviewerId);
        dto.setResult(result);
        dto.setComment(comment);
        dto.setInterviewerName(interviewerName);
        dto.setDepartmentName(departmentName);
        dto.setIsParticipated(isParticipated);
        return dto;
    }
}

DTO

@Data
@NoArgsConstructor
public class InterviewCommentDTO implements Serializable {
    private Integer interviewId;
    private String interviewerId;
    private Boolean result;
    private String comment;
    private String interviewerName;
    private String departmentName;
    private Boolean isParticipated;

    public static InterviewCommentDTO InterviewCommentDO2InterviewCommentDTO(InterviewCommentDO interviewCommentDO) {
        InterviewCommentDTO dto = new InterviewCommentDTO();
        BeanUtil.copyProperties(interviewCommentDO, dto);
        return dto;
    }
}

DO

@Data
@NoArgsConstructor
@AllArgsConstructor
public class InterviewCommentDO implements Serializable {
    private Integer interviewId;
    private String interviewerId;
    private Boolean result;
    private String comment;
    private String interviewerName;
    private String departmentName;
    private Boolean isParticipated;
}

你可能感兴趣的:(状态模式,java)