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

天猫整站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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/418810.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Java 图片流和base64互转

https://www.jianshu.com/p/ffb1f7e85530

ParameterizedType应用,利用java反射获取参数化类型的class实例

https://blog.csdn.net/ltaihyy/article/details/78211274 public class TestParameterizedType extends RequestApiParam<UserDispatchMakeInfoDTO1> {public static void main(String[] args) {Class clazz1TestParameterizedType.class;/*** 父类的参数类型不能是泛型…

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

天猫整站SSM-后台分类管理-增加&#xff08;做个人学习笔记整理用&#xff09; CategoryController&#xff1a; request.getSession().getServletContext()// 获取的是page的上下文。 request.getSession().getServletContext().getRealPath(“”); 是获取的的tamcat的路径&a…

Java中的Type接口和Class类有什么区别

https://blog.csdn.net/linghuainian/article/details/86137810

canvas 在线画图

canvas 在线画图 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>Title</title><style type"text/css">/*画图大师来了*/#cans{border:1px solid red;}</style><scrip…

java使用validator进行校验

https://blog.csdn.net/dream_broken/article/details/53584169 public class BeanValidator {// private static Validator validator SpringContextHolder.getBean(Validator.class);/*** 验证某个bean的参数** throws ValidationException 如果参数校验不成功则抛出此异…

Delphi iOS 开启文件共享 UIFileSharingEnabled

Apple 在 iOS 提供了文件共享&#xff08;FileSharing&#xff09;功能&#xff0c;让 App 有一个对外窗口的目录&#xff0c;透过 iTunes 可以任意管理这个目录的文档内容&#xff08;可拖入文档&#xff0c;也能将文档拖出备份&#xff09;。 如果 App 需要文件共享&#xff…

iOS:iOS开发系列–打造自己的“美图秀秀”(中)

来源&#xff1a; KenshinCui 链接&#xff1a;http://www.cnblogs.com/kenshincui/p/3959951.html 其他状态设置 常用的图形上下文状态设置上面基本都用到了&#xff0c;我们不再一一解释&#xff0c;这里着重说一下叠加模式和填充模式&#xff0c;初学者对于这两个状态设置…

Validator 使用总结

https://blog.csdn.net/weixin_37509652/article/details/80676693

ubuntu ifconfig只有lo没有ens33的问题

如果ifconfig只显示了lo&#xff0c; ifconfig -a 却正常显示ens33。那么可以按照如下的操作&#xff1a; service network-manager stop rm /var/lib/NetworkManager/NetworkManager.state service network-manager start 即可恢复网络连接

Spring4.0学习笔记(3) —— Spring_Bean之间的关系

1、继承关系 bean-relation.xml <?xml version"1.0" encoding"UTF-8"?> <beansxmlns"http://www.springframework.org/schema/beans"xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xmlns:p"http://www.spring…

tftp ping 不通。无法访问目标主机

在开发板的烧录过程中&#xff0c;我们会使用tftp服务来下载.bin文件到开发板上&#xff0c;但是用网线把电脑和开发板连接起来&#xff0c;开发板ping不通电脑&#xff08;电脑连的是无线网&#xff0c;ping 无线网的ip&#xff09;。但是把无线网关闭后&#xff0c;设置电脑本…

作业3(学习进度表)【第四周】

第四周总结学习成长经历 周数 专业学习目标 专业学习时间 新增代码量 博客发表量 人文方面学习 知识技能总结 第四周 这学期新增了HTML5的课程&#xff0c;对这门课程挺感兴趣的&#xff0c;但是上课比较跟不上老师的节奏&#xff0c;而且基础理论课上的少有些基本…

Springboot@Configuration和@Bean详解

https://www.cnblogs.com/javafucker/p/10148464.html

踩坑记录--VScode编辑不同文件没有及时crtl+s,导致文件修改无效

谷粒商城P43 多次修改路由不生效&#xff0c;原来是修改了路由文件没有crtls保存

移动端去掉按钮点击热区

对于ios系统上的浏览器&#xff0c;如果某处实现了点击事件&#xff0c;则在点击该区域的时候&#xff0c;会有蓝边&#xff0c;而这种蓝边的效果有时候不是我们前端设计人员真正期望的点击效果 所以我们需要考虑将这样的蓝边去掉&#xff0c; .click_elm{ outline:none; -webk…

Java拦截器,过滤器,监听器(三大器)对比

https://blog.csdn.net/baidu_20876831/article/details/80405515

谷粒商城--API三级分类--查询--递归树形结构获取

是先把所有分类信息获取到内存&#xff0c;再递归处理&#xff0c;把分类数据封装成树形结构的数据&#xff0c;返回前台。 用到jdk1.8里面的流式编程和lamda表达式。要想理清这里的逻辑处理&#xff0c;先去把上面那两个东西学习一下。