Background static page management
1. Integrate static pages
Static page location: background management system static page
Instructions:
Add the page and CSS and JS to the buy-manager-web project under WEB-INF:
Since the url interception form defined in web.xml is "/", it means to intercept all url requests, including static resources such as css, js and so on. So you need to add the resource mapping tag in springmvc.xml:
<!-- Configure resource mapping --> <mvc:resources location="/css/" mapping="/css/**"/> <mvc:resources location="/js/" mapping="/js/**"/> |
Paging plugin PageHelper
1. Mybatis paging plugin - PageHelper description
If you are also using Mybatis, it is recommended to try this paging plugin, which must be the most convenient paging plugin to use.
The plugin currently supports Oracle, Mysql, MariaDB, SQLite, Hsqldb, PostgreSQL six database paging.
2. How to use
Step 1: Add a reference to PageHelper in pom in manager-dao
<!-- Paging plugin--> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> </dependency> |
Step 2: Configure the interceptor plugin in the Mybatis configuration xml:
<plugins> <!-- Configure paging plugin --> <plugin interceptor="com.github.pagehelper.PageHelper"> <!-- Set database dialect --> <property name="dialect" value="mysql" /> </plugin> </plugins> |
Step 3: Pagination test is used in the code
1. Set paging information:
//Get the first page, 10 pieces of content, the default query total count PageHelper.startPage(1, 10); //The first select method that follows will be paged List<Country> list = countryMapper.selectIf(1); |
2. Get paging information
//After paging, the actual returned result list type is Page<E>, if you want to take out the paging information, you need to cast it to Page<E>, Page<Country> listCountry = (Page<Country>)list; listCountry.getTotal (); |
3. The second method of getting paging information
//获取第 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; } |