Java Code Examples for com.jfinal.plugin.activerecord.Page#getPageNumber()

The following examples show how to use com.jfinal.plugin.activerecord.Page#getPageNumber() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonUtils.java    From my_curd with Apache License 2.0 5 votes vote down vote up
/**
 * Page<Record>转为Page<Map<String, Object>>,驼峰命名
 *
 * @param records
 * @return
 */
public static Page<Map<String, Object>> recordsToCamelCaseMaps(Page<Record> records) {
    List<Record> recordList = records.getList();
    List<Map<String, Object>> maps = new ArrayList<>();
    for (Record record : recordList) {
        maps.add(recordToCamelCaseMap(record));
    }
    return new Page<>(maps, records.getPageNumber(), records.getPageSize(),
            records.getTotalPage(), records.getTotalRow());
}
 
Example 2
Source File: JsonUtils.java    From my_curd with Apache License 2.0 5 votes vote down vote up
/**
 * Page<Page<? extends Model>转为Page<Map<String, Object>>,驼峰命名
 *
 * @param models
 * @return
 */
public static Page<Map<String, Object>> modelsToCamelCaseMaps(Page<? extends Model> models) {
    List<? extends Model> modelList = models.getList();
    List<Map<String, Object>> maps = new ArrayList<>();
    for (Model model : modelList) {
        maps.add(modelToCamelCaseMap(model));
    }
    return new Page<>(maps, models.getPageNumber(), models.getPageSize(), models.getTotalPage(),
            models.getTotalRow());
}
 
Example 3
Source File: PaginateDirectiveBase.java    From jboot with Apache License 2.0 4 votes vote down vote up
@Override
public void onRender(Env env, Scope scope, Writer writer) {

    String previousClass = getPara(PREVIOUS_CLASS_KEY, scope, DEFAULT_PREVIOUS_CLASS);
    String nextClass = getPara(NEXT_CLASS_KEY, scope, DEFAULT_NEXT_CLASS);
    String activeClass = getPara(ACTIVE_CLASS_KEY, scope, DEFAULT_ACTIVE_CLASS);
    String disabledClass = getPara(DISABLED_CLASS_KEY, scope, DEFAULT_DISABLED_CLASS);
    boolean onlyShowPreviousAndNext = getParaToBool(ONLY_SHOW_PREVIOUS_AND_NEXT_KEY, scope, false);

    String previousText = getPara(PREVIOUS_TEXT_KEY, scope, DEFAULT_PREVIOUS_TEXT);
    String nextText = getPara(NEXT_TEXT_KEY, scope, DEFAULT_NEXT_TEXT);
    String pageItemsName = getPara(PAGE_ITEMS_NAME_KEY, scope, DEFAULT_PAGE_ITEMS_NAME);


    Page<?> page = getPage(env, scope, writer);

    int currentPage = page == null ? 1 : page.getPageNumber();
    int totalPage = page == null ? 1 : page.getTotalPage();

    if ((totalPage <= 0) || (currentPage > totalPage)) {
        return;
    }

    int startPage = currentPage - 4;
    if (startPage < 1) {
        startPage = 1;
    }
    int endPage = currentPage + 4;
    if (endPage > totalPage) {
        endPage = totalPage;
    }

    if (currentPage <= 8) {
        startPage = 1;
    }

    if ((totalPage - currentPage) < 8) {
        endPage = totalPage;
    }

    List<PaginateItem> pages = new ArrayList<PaginateItem>();
    if (currentPage == 1) {
        pages.add(new PaginateDirectiveBase.PaginateItem(previousClass + StrUtil.SPACE + disabledClass, JAVASCRIPT_TEXT, previousText));
    } else {
        pages.add(new PaginateDirectiveBase.PaginateItem(previousClass, getUrl(currentPage - 1, env, scope, writer), previousText));
    }

    if (currentPage > 8 && !onlyShowPreviousAndNext) {
        pages.add(new PaginateDirectiveBase.PaginateItem(StrUtil.EMPTY, getUrl(1, env, scope, writer), 1));
        pages.add(new PaginateDirectiveBase.PaginateItem(StrUtil.EMPTY, getUrl(2, env, scope, writer), 2));
        pages.add(new PaginateDirectiveBase.PaginateItem(disabledClass, JAVASCRIPT_TEXT, ELLIPSIS_TEXT));
    }

    if (!onlyShowPreviousAndNext) {
        for (int i = startPage; i <= endPage; i++) {
            if (currentPage == i) {
                pages.add(new PaginateDirectiveBase.PaginateItem(activeClass, JAVASCRIPT_TEXT, i));
            } else {
                pages.add(new PaginateDirectiveBase.PaginateItem(StrUtil.EMPTY, getUrl(i, env, scope, writer), i));
            }
        }
    }

    if ((totalPage - currentPage) >= 8 && !onlyShowPreviousAndNext) {
        pages.add(new PaginateDirectiveBase.PaginateItem(disabledClass, JAVASCRIPT_TEXT, ELLIPSIS_TEXT));
        pages.add(new PaginateDirectiveBase.PaginateItem(StrUtil.EMPTY, getUrl(totalPage - 1, env, scope, writer), totalPage - 1));
        pages.add(new PaginateDirectiveBase.PaginateItem(StrUtil.EMPTY, getUrl(totalPage, env, scope, writer), totalPage));
    }

    if (currentPage == totalPage) {
        pages.add(new PaginateDirectiveBase.PaginateItem(nextClass + StrUtil.SPACE + disabledClass, JAVASCRIPT_TEXT, nextText));
    } else {
        pages.add(new PaginateDirectiveBase.PaginateItem(nextClass, getUrl(currentPage + 1, env, scope, writer), nextText));
    }

    scope.setLocal(pageItemsName, pages);
    renderBody(env, scope, writer);
}