分頁插件與網頁靜態管理

後臺靜態頁面管理

1、整合靜態頁面

靜態頁面位置:後臺管理系統靜態頁面

 

使用方法:

把頁面和 CSS 和 JS 添加到 buy-manager-web 工程中的 WEB-INF 下:

由於在 web.xml 中定義的 url 攔截形式爲“/”表示攔截所有的 url 請求,包括靜態資源例如css、js 等。所以需要在 springmvc.xml 中添加資源映射標籤:

<!-- 配置資源映射 -->

 <mvc:resources location="/css/" mapping="/css/**"/>

 <mvc:resources location="/js/" mapping="/js/**"/>

 

分頁插件PageHelper

1、 Mybatis 分頁插件 - PageHelper 說明

如果你也在用 Mybatis,建議嘗試該分頁插件,這個一定是最方便使用的分頁插件。

該插件目前支持Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL 六種數據庫分頁。

2、使用方法

第一步:在 manager-dao 中pom添加對 PageHelper 的引用

<!-- 分頁插件 -->

 <dependency>

 <groupId>com.github.pagehelper</groupId>

 <artifactId>pagehelper</artifactId>

 </dependency>

第二步:在 Mybatis 配置 xml 中配置攔截器插件:

<plugins>

      <!-- 配置分頁插件 -->

      <plugin interceptor="com.github.pagehelper.PageHelper">

        <!-- 設置數據庫方言 -->

        <property name="dialect" value="mysql" />

      </plugin>

   </plugins>

 第三步:分頁測試在代碼中使用

1、         設置分頁信息:

//獲取第 1 頁,10 條內容,默認查詢總數 count

 PageHelper.startPage(1, 10);

//緊跟着的第一個 select 方法會被分頁

List<Country> list = countryMapper.selectIf(1);

2、取分頁信息

//分頁後,實際返回的結果 list 類型是 Page<E>,如果想取出分頁信息,需要強制轉換爲 Page<E>,

Page<Country> listCountry = (Page<Country>)list;

listCountry.getTotal();

3、取分頁信息的第二種方法

//獲取第 1頁,10 條內容,默認查詢總數 count

PageHelper.startPage(1, 10);

List<Country> list = countryMapper.selectAll();

//用 PageInfo 對結果進行包裝

PageInfo page = new PageInfo(list);

//測試 PageInfo 全部屬性

//PageInfo 包含了非常全面的分頁屬性

assertEquals(1, page.getPageNum());

assertEquals(10, page.getPageSize());

assertEquals(1, page.getStartRow());

assertEquals(10, page.getEndRow());

assertEquals(183, page.getTotal());

assertEquals(19, page.getPages());

assertEquals(1, page.getFirstPage());

assertEquals(8, page.getLastPage());

assertEquals(true, page.isFirstPage());

assertEquals(false, page.isLastPage());

assertEquals(false, page.isHasPreviousPage());

assertEquals(true, page.isHasNextPage());

Service 層

參數:int page ,int rows

業務邏輯:查詢所有商品列表,要進行分頁處理。

返回值:EasyUIDataGridResult

/**

 * @Title: getItemList

 * @Description: TODO(這裏用一句話描述這個方法的作用)

 * @param page

 * @param rows

 * @return

 * @see com.igeek.service.ItemService#getItemList(int, int)

 */

public EasyUIDataGridResult getItemList(int page, int rows) {

 EasyUIDataGridResult result = null;

 //設置分頁的頁面和每頁條數

 PageHelper.startPage(page,rows);

//執行查詢

 TbItemExample example = new TbItemExample();

 List<TbItem> list = itemMapper.selectByExample(example);

 //封裝分頁結果

 PageInfo<TbItem> info = new PageInfo<>(list);

 //生成返回值

 result = new EasyUIDataGridResult(info.getTotal(), list);

 return result;

 }

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章