MyBatisPlus的通用查詢,簡直能夠丟棄Dao和mapper.xml了

/**
 *
 * @author shenjing
 * @date 2018/6/20
 */
@Service
public class LocalDispatchServiceImpl extends ServiceImpl<Rep_DisPatchDao, Rep_DisPatch> implements LocalDispatchService {
    /**
     * 根據domain組合各類類型的查詢,通常的查詢就能夠經過這個完成了,dao徹底沒有存在的意義了
     *
     * @param domain
     * @return
     */
    @Override
    public Rep_DisPatch findOneByDomain(Rep_DisPatch domain) {
        EntityWrapper<Rep_DisPatch> eWrapper = new EntityWrapper<>(domain);
        return selectOne(eWrapper);
    }

    /**
     * 根據分頁參數進行查詢
     *
     * @param dispatchPageParam
     * @return
     */
    @Override
    public Page<Rep_DisPatch> findListByPage(DispatchPageParam dispatchPageParam) {
        Page<Rep_DisPatch> page = new Page<>(dispatchPageParam.getPageIndex(), dispatchPageParam.getPageSize());
        EntityWrapper<Rep_DisPatch> eWrapper = new EntityWrapper<>(dispatchPageParam.getObj());
        Page<Rep_DisPatch> ret = selectPage(page, eWrapper);
        return ret;
    }

}

  此處ServiceImpl,是myBatisPlus提供的一個基類。java

DispatchPageParam 是本身寫的一個查詢參數的封裝

/**
 * 基礎分頁參數
 * @author shenjing
 * @date 2018/6/20
 */
public class BasePageParam<T> {
    T obj;

    int pageIndex;

    int pageSize;

    public T getObj() {
        return obj;
    }

    public void setObj(T obj) {
        this.obj = obj;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
}

  實際上這個裏面什麼都沒有,只要繼承基類就能夠了app

/**
 * Created by shenjing on 2018/6/20.
 */
public class DispatchPageParam extends BasePageParam<Rep_DisPatch> {

}
相關文章
相關標籤/搜索