mercredi 16 janvier 2019

I don't konw if this code is an Adapter Pattern?

PageInfo class

public class PageInfo<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private int pageNum;
    private int pageSize;
    private int size;
    private int startRow;
    private int endRow;
    private long total;
    private int pages;
    private List<T> list;
}

ResponseDto class

public class ResponseDto<T> implements Serializable {

    private String msg = "success";

    private int code = SUCCESS;

    private T data;
}

PageResponseDto class

public class PageResponseDto<T> extends ResponseDto<List<T>> {

    private int pageNum;

    private int pageSize;

    private int size;

    private long total;

    private int pages;

    public PageResponseDto() {
        super();
    }

    public PageResponseDto(PageInfo<T> p) {
        super(p.getList());
        this.pageNum = p.getPageNum();
        this.pageSize = p.getPageSize();
        this.size = p.getSize();
        this.total = p.getTotal();
        this.pages = p.getPages();
    }
}

use

public PageResponseDto<OrderDto> findStoreOrderByPage(Integer pageNum, Integer pageSize) {
    PageHelper.startPage(pageNum, pageSize);
    List<OrderDto> storeOrderList = basicDataMapper.findStoreOrderByPage();
    PageInfo<OrderDto> p = new PageInfo<>(storeOrderList);
    return new PageResponseDto<>(p);
}

Because the system has a uniform return class 'ResponseDto',I want to transform the class PageInfo to ResponseDto.So wrote this code.I hava a question that this code can be called Adapter Pattern? If not, does this code use design patterns? Or what should this conversion be called?

Aucun commentaire:

Enregistrer un commentaire