日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/10 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 天猫整站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

總結

以上是生活随笔為你收集整理的天猫整站SSM-分页-总结(做个人学习笔记整理用)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。