天猫整站SSM-分页-herf(做个人学习笔记整理用)

先写Page.java

package com.how2java.tmall.util;public class Page {private int start; //开始页数private int count; //每页显示个数private int total; //总个数private String param; //参数private static final int defaultCount = 5; //默认每页显示5条public int getStart() {return start;}public void setStart(int start) {this.start = start;}public int getCount() {return count;}public void setCount(int count) {this.count = count;}public Page (){count = defaultCount;}public Page(int start, int count) {this();this.start = start;this.count = count;}public boolean isHasPreviouse(){if(start==0)return false;return true;}public boolean isHasNext(){if(start==getLast())return false;return true;}public int getTotalPage(){int totalPage;// 假设总数是50,是能够被5整除的,那么就有10页if (0 == total % count)totalPage = total /count;// 假设总数是51,不能够被5整除的,那么就有11页elsetotalPage = total / count + 1;if(0==totalPage)totalPage = 1;return totalPage;}public int getLast(){int last;// 假设总数是50,是能够被5整除的,那么最后一页的开始就是45if (0 == total % count)last = total - count;// 假设总数是51,不能够被5整除的,那么最后一页的开始就是50elselast = total - total % count;last = last<0?0:last;return last;}@Overridepublic String toString() {return "Page [start=" + start + ", count=" + count + ", total=" + total + ", getStart()=" + getStart()+ ", getCount()=" + getCount() + ", isHasPreviouse()=" + isHasPreviouse() + ", isHasNext()="+ isHasNext() + ", getTotalPage()=" + getTotalPage() + ", getLast()=" + getLast() + "]";}public int getTotal() {return total;}public void setTotal(int total) {this.total = total;}public String getParam() {return param;}public void setParam(String param) {this.param = param;}}

再写CategoryMapper.xml:修改CategoryMapper.xml,以提供带分页的查询语句和获取总数的sql语句

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.how2java.tmall.mapper.CategoryMapper"><select id="list" resultType="Category">select * from   category         order by id desc<if test="start!=null and count!=null">limit #{start},#{count}</if></select><select id="total" resultType="int">select count(*) from category</select>
</mapper>

接着写CategoryMapper

package com.how2java.tmall.mapper;import com.how2java.tmall.util.Page;
import com.how2java.tmall.pojo.Category;import java.util.List;public interface CategoryMapper {public List<Category> list(Page page);public int total();
}

CategoryService

package com.how2java.tmall.service;import com.how2java.tmall.pojo.Category;
import com.how2java.tmall.util.Page;
import java.util.List;public interface CategoryService{int total();List<Category> list(Page page);
}

CategoryServiceImpl

package com.how2java.tmall.service.impl;
import com.how2java.tmall.util.Page;
import com.how2java.tmall.mapper.CategoryMapper;
import com.how2java.tmall.pojo.Category;
import com.how2java.tmall.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class CategoryServiceImpl  implements CategoryService {@AutowiredCategoryMapper categoryMapper;@Overridepublic List<Category> list(Page page) {return categoryMapper.list(page);}@Overridepublic int total() {return categoryMapper.total();}
}

CategoryController

package com.how2java.tmall.controller;import com.how2java.tmall.pojo.Category;
import com.how2java.tmall.service.CategoryService;
import com.how2java.tmall.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;import java.util.List;@Controller
@RequestMapping("")
public class CategoryController {@AutowiredCategoryService categoryService;@RequestMapping("admin_category_list")public String list(Model model,Page page){List<Category> cs= categoryService.list(page);int total = categoryService.total();page.setTotal(total);model.addAttribute("cs", cs);model.addAttribute("page", page);return "admin/listCategory";}}

listCategory.jsp

天猫整站SSM-分页-总结(做个人学习笔记整理用)相关推荐

  1. 天猫整站SSM-分页-herf(做个人学习笔记整理用)

    天猫整站SSM-分页-(做个人学习笔记整理用) <li ><a href="?start=${page.start-page.count}" aria-label ...

  2. 天猫整站SSM项目(三)后台demo---数据查询(一)

    天猫整站SSM项目(三)后台demo---数据查询(一 一.分类查询页面包含的jsp文件 二.查询功能的实现 到这里就开始讲解功能开发了. 开发整站的顺序,通常来说还是按照依赖性来进行,前端需要的数据 ...

  3. 天猫整站SSM项目(二)数据库设计

    天猫整站SSM项目(二)数据库设计 一.数据库设计分析 二.创建数据库 1. 建立数据库 2. 表与表之间的关系 2.1 表![在这里插入图片描述](https://img-blog.csdnimg. ...

  4. 天猫整站SSM-后台分类管理-增加(做个人学习笔记整理用)

    天猫整站SSM-后台分类管理-增加(做个人学习笔记整理用) CategoryController: request.getSession().getServletContext()// 获取的是pag ...

  5. 天猫整站SSM-分页-limit(做个人学习笔记整理用)

    数据库使用的是mysql 要想在Mybatis中使用分页查询,首先要清楚mysql中limit的用法. limit a,b a是从第a+1条数据开始,b是指读取几条数据 例如:select * fro ...

  6. 终于稀里糊涂完成了模仿天猫整站ssm

    1.首先感谢How2J的SSM教程. 2.其次分享一下图片 3.互勉加油

  7. springboot+veu实战项目-天猫整站

    目录 天猫整站 Springboot 一:技术准备 二:开发流程 三:本地演示 1 : 下载并运行 2 : 访问地址 3 : nginx 4 : nginx.conf 配置文件 5 : 启动nginx ...

  8. 天猫整站Springboot 从零开始搭建(二)

    目录 1 技术准备 2 开发流程 2.1 需求分析 2.2.1 需求分析-展示 2.2.2 需求分析-交互 2.2.3 需求分析-后台 2.2 表结构设计 2.3 原型 2.4 后台-分类管理 2.4 ...

  9. SpringBoot实战项目教程----springboot天猫整站

    目录 一:技术准备 二:开发流程 三:本地演示 1 : 下载并运行 2 : 访问地址 3 : nginx 4 : nginx.conf 配置文件 5 : 启动nginx 6 : 访问测试 7 : 动静 ...

最新文章

  1. TensorRT-8量化分析
  2. JavaScript DOM操作表格及样式
  3. windows server 网络负载均衡配置
  4. 【详细解读】CSS渐变用法——Web前端系列学习笔记
  5. esri geometry-api-java的maven创建
  6. User Stories - 最佳实践 (Best Practices)
  7. 启动nginx服务报错Job for nginx.service failed because the control process exited with error code.
  8. 3 FI配置-企业结构-分配-给公司分配公司代码
  9. Mysql(二)——简单查询及示例
  10. varnish几个工具命令行工作情况
  11. windows下dlib库简介、安装问题解决及简单小例子 (python)
  12. 基于Qt的UDP协议实现及解析数据
  13. 测控技术与仪器是计算机相关的,测控技术与仪器专业
  14. Lasso估计学习笔记(二)
  15. 计算机机房安全设计规范,弱电机房建设规范要求
  16. cnnvd爬取漏洞信息
  17. 【电机测速】M法、T法、M/T法测速系统设计实现
  18. dos2unix命令详解
  19. 一文搞懂AWS EC2, IGW, RT, NAT, SG 基础篇下
  20. ReSharper配置及用法

热门文章

  1. 第五十期:详解语音识别技术的发展
  2. tomcat:Cannot find /usr/local/tomcat1/bin/setclasspath.sh
  3. 某测试仪控制系统的设计方案--ARM+FPGA+NIOS
  4. vue-cli3使用svg图标的详细步骤
  5. python网格划分_在python中创建一个2d网格
  6. 用python写helloworld_Python Helloworld程序简单实现
  7. js基础---js组成以及基本认知
  8. java学习笔记④MySql数据库--03/04 DQL查询
  9. sql 查询结果自定义排序
  10. GO语言-基础语法:条件判断