根据一级标题查询书本的信息

根据一级标题查询二级标题的信息

根据二级标题查询书本的信息

根据二级标题查询一级标题的信息

分页查询

Mapper

    //编辑推荐 根据销量查询前二少public List<Book> selectBookByEdit();//热销推荐 根据销量查询前三多public List<Book> selectBookByHotBuy();//最新上架 根据日期查询前三新public List<Book> selectBookByNewDate();//新书热卖 根据日期降序销量降序取前二public List<Book> selectBookByNewDateAndHotBuy();//根据id查询public Book selectBookById(Integer id);//查询一级类别分页展示数据List<Book> selectBookByPageLevelOne(@Param("categoryId") Integer categoryId, @Param("pageIndex") Integer pageIndex, @Param("pageSize") Integer pageSize);//查询二级类别 分页展示数据List<Book> selectBookByPageLevelTwo(@Param("categoryId") Integer categoryId, @Param("pageIndex") Integer pageIndex, @Param("pageSize") Integer pageSize);//查询一级类别总条数Integer selectBookByLevelOne(@Param("categoryId") Integer categoryId);//查询二级类别总条数Integer selectBookByLevelTwo(@Param("categoryId")Integer categoryId);public interface CategoryMapper {//查询所有类别public List<Category> selectAllCategory();//根据一级分类id查询二级分类public Category selectCategoryById(Integer id);//查询一级分类的图书public List<Book> selectBookByLevelOne(Integer id);//根据二级分类id查询一级分类public Integer selectLevelOneByTwo(Integer id);//根据二级分类查询图书public List<Book> selectBookByLevelTwo(Integer id);//查询二级分类的图书个数public List<Category> selectLevelTwoNum(Integer id);}

SQL/Mapper

    Book:<select id="selectBookByPageLevelOne" resultMap="bookResultMap">select * from d_bookwhere cid in(select category_id from d_category where parent_id=#{categoryId})limit #{pageIndex},#{pageSize}</select><select id="selectBookByPageLevelTwo" resultMap="bookResultMap">select * from d_bookwhere cid=#{categoryId}limit #{pageIndex},#{pageSize}</select><select id="selectBookByLevelOne" resultType="java.lang.Integer">select count(*) from d_bookwhere cid in(select category_id from d_category where parent_id=#{categoryId})</select><select id="selectBookByLevelTwo" resultType="java.lang.Integer">select count(*) from d_book where cid=#{categoryId}</select>Category:<select id="selectAllCategory" resultMap="categoryResultMap">select father.*,child.category_id cid,child.category_name cnamefrom d_category father inner join d_category childon child.parent_id = father.category_id</select><select id="selectCategoryById" resultMap="categoryResultMap">select father.*,child.category_id cid,child.category_name cnamefrom d_category father inner join d_category childon child.parent_id = father.category_id where father.category_id = #{id}</select><select id="selectBookByLevelOne"             resultMap="com.baizhi.mapper.BookMapper.bookResultMap">select * from d_book where cid in(select child.category_id from d_category father INNER JOIN d_category childon child.parent_id = father.category_id where father.category_id = #{id})</select><select id="selectLevelTwoNum" resultMap="categoryResultMap">select c.category_id,c.category_name,count(book_id) book_count from d_book b         RIGHT JOIN d_category c ON b.cid = c.category_idwhere c.parent_id=#{id} GROUP BY c.category_id</select><select id="selectBookByLevelTwo" resultMap="com.baizhi.mapper.BookMapper.bookResultMap">select * from d_book where cid=#{id}</select><select id="selectLevelOneByTwo" resultType="java.lang.Integer">select father.category_id from d_category father left join d_category child on father.category_id = child.parent_id where child.category_id = #{id}</select>

Controller

@RequestMapping("/showMain")public String showAll(Model model, HttpSession session) {User user = (User) session.getAttribute("user");if (user!=null){List<Book> editBooks = bookService.selectBookByEdit();List<Book> hotBooks = bookService.selectBookByHotBuy();List<Book> newBooks = bookService.selectBookByNewDate();List<Book> newHotBooks = bookService.selectBookByNewDateAndHotBuy();model.addAttribute("editBooks", editBooks);model.addAttribute("hotBooks", hotBooks);model.addAttribute("newBooks", newBooks);model.addAttribute("newHotBooks", newHotBooks);//类别List<Category> categories = categoryService.selectAllCategory();model.addAttribute("categories", categories);return "/main/main";}else {return "user/login_form";}}
//分页Controller实现@RequestMapping("selectBookByOne")private String selectBookByOne(Integer categoryId,Integer pageIndex,Integer pageSize,Model model) {//查询一级标题下的二级标题List<Category> categories = categoryService.selectLevelTwoNum(categoryId);model.addAttribute("categories", categories);Category category = categoryService.selectCategoryById(categoryId);model.addAttribute("category", category);List<Book> books = bookService.selectBookByPageLevelOne(categoryId, pageIndex, pageSize);model.addAttribute("books",books);//书本总数Integer integer = bookService.selectBookByLevelOne(categoryId);//页数int totalPage = 0;if (integer%pageSize==0){totalPage = integer/pageSize;}else {totalPage = integer/pageSize+1;}//当前页model.addAttribute("method","selectBookByOne.do");model.addAttribute("pageIndex",pageIndex);//categoryIdmodel.addAttribute("c",categoryId);model.addAttribute("integer",integer);model.addAttribute("totalPage",totalPage);return "main/book_list";}@RequestMapping("selectBookByTwo")private String selectBookByTwo(Integer categoryId,Integer pageIndex,Integer pageSize,Model model) {Integer i = categoryService.selectLevelOneByTwo(categoryId);//查询分类Category category = categoryService.selectCategoryById(i);model.addAttribute("category", category);//查询二级分类的图书个数List<Category> categories = categoryService.selectLevelTwoNum(i);model.addAttribute("categories", categories);//查询二级分类的图书总个数Integer sum = 0;for (Category c : categories) {sum += c.getBookCount();}model.addAttribute("sum", sum);//二级标题下的所有图书List<Book> books = bookService.selectBookByPageLevelTwo(categoryId, pageIndex, pageSize);model.addAttribute("books",books);System.out.println(pageIndex);//书本总数Integer integer = bookService.selectBookByLevelTwo(categoryId);//页数int totalPage = 0;if (integer%pageSize==0){totalPage = integer/pageSize;}else {totalPage = integer/pageSize+1;}System.out.println(totalPage);model.addAttribute("method","selectBookByTwo.do");//当前页model.addAttribute("pageIndex",pageIndex);//categoryIdmodel.addAttribute("c",categoryId);model.addAttribute("integer",integer);model.addAttribute("totalPage",totalPage);return "main/book_list";}

JSP

<c:forEach items="${categories}" var="category">[<a href='${pageContext.request.contextPath}/book/selectBookByOne.do?        categoryId=${category.id}&pageIndex=1&pageSize=5'>${category.name}</a>]
<c:forEach items="${category.child}" var="child"><a href='${pageContext.request.contextPath}/book/selectBookByTwo.do?categoryId=${child.id}&pageIndex=1&pageSize=5'>${child.name}</a>
</c:forEach>
<c:if test="${pageIndex>1}"><div class='list_r_title_text3a'><a name=link_page_next href="${pageContext.request.contextPath}/book/${method}?categoryId=${c}&pageIndex=${pageIndex-1}&pageSize=5"><img src='../images/page_up.gif' /> </a></div>
</c:if>

当当网Day2-Day3相关推荐

  1. jQuery - 当当网我的订单页

    <!DOCTYPE html> <html> <head lang="en"><meta charset="UTF-8" ...

  2. 重构当当网交易系统!

    作者:王胜军,当当网交易系统开发经理! 来自:数人云 近年来电商巨头定义的购物节变得越来越多,双十一.双十二已然成为举国同庆的大日子.然而,当我们把一件件磨人的"小妖精"放进购物车 ...

  3. 当当网强烈谴责李国庆有关刘强东案言论

    雷帝网 乐天 12月24日报道 当当网今日发布声明,称李国庆是当当网联合创始人,他离开当当网管理层.决策层已有一段时间. "李国庆先生的言论是他的个人观点,当当网已经要求李国庆将当当logo ...

  4. 美媒评全球十家增速最快IT办事公司 当当网居首

    网易科技讯 2月27日动静,美国财经网站Cnanalyst周六评选出全球收益增速最快的十支IT办事行业股票,评选结局根据华尔街券商分析师对各支股票的每股收益年均增长率的预计.当当网.百度和文思信息三家 ...

  5. 在当当买了python怎么下载源代码-爬虫实战一:爬取当当网所有 Python 书籍

    图片来自 unsplash 我们已经学习 urllib.re.BeautifulSoup 这三个库的用法.但只是停留在理论层面上,还需实践来检验学习成果.因此,本文主要讲解如何利用我们刚才的几个库去实 ...

  6. 在当当买了python怎么下载源代码-Python爬取当当网APP数据

    本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理 以下文章来源于AirPython ,作者星安果 目标 场景:有时候通过传统的方法去 ...

  7. 在当当买了python怎么下载源代码-python爬虫爬取当当网

    [实例简介]python爬虫爬取当当网 [实例截图] [核心代码] ''' Function: 当当网图书爬虫 Author: Charles 微信公众号: Charles的皮卡丘 ''' impor ...

  8. 在当当买了python怎么下载源代码-爬虫实战:爬取当当网所有 Python 书籍

    来源:公众号-极客猴 出处: 本文主要讲解如何利用urllib.re.BeautifulSoup 这几个库去实战,爬取当当网所有 Python 书籍. 1 确定爬取目标 任何网站皆可爬取,就看你要不要 ...

  9. 当当网新用户注册界面——JS代码

    <span style="color:#ff9966;"><span style="font-size: 32px;"><stro ...

  10. 我的第一个Scrapy 程序 - 爬取当当网信息

    前面已经安装了Scrapy,下面来实现第一个测试程序. 概述 Scrapy是一个爬虫框架,他的基本流程如下所示(下面截图来自互联网) 简单的说,我们需要写一个item文件,定义返回的数据结构:写一个s ...

最新文章

  1. 使用C++的Socket实现从客户端到服务端,服务端到客户端传输文件
  2. HTML中a标签/超链接标签的下划线怎么去掉
  3. [转]memset用法详解
  4. thinkphp仿素材火教程_国外都用古风效果图获奖了,为什么你连素材都没有?
  5. javaweb开发1.环境配置(javaweb插件下载及tomact在eclips中配置)
  6. Sequelize-nodejs-8-Transactions
  7. iPhoneiPad DFU及恢复模式刷机、降级教程
  8. 算法竞赛入门经典经典例题及习题题解
  9. matlab实现同态滤波
  10. mfc入门程序之简单的计算器
  11. 【博客分享】优秀的有趣的博客
  12. 思岚A1激光雷达的测试(windows)
  13. 51单片机一些软件的使用
  14. 手机开发者选项各项参数意义
  15. 扫福活动开始,你的公众号图文排版也要“福”气满满
  16. 跟我一起学-Python爬取(酷我)
  17. 图像分割中的Dice Loss
  18. CSS中表示cellpadding和cellspacing的方法
  19. java毕业设计 springboo疫情温度打卡健康评测系统 (3)系统后台管理功能
  20. 互联网行业常见数据分类:用户数据、行为数据、业务数据

热门文章

  1. 戴森发新品:看着像耳机,其实是个口罩
  2. 三国之见龙卸甲……古今多少事,都付笑谈中
  3. s3c2440 ARM9 裸机驱动第一篇-GPIO驱动(汇编)
  4. 纳昇电子:PEDOT-PSS 材料国产化之空穴传输层
  5. jQuery实现table表格中行数据上下拖拽功能
  6. 关于淘宝联盟的接口调用报错问题
  7. 1007 素数对猜想 (20 分)
  8. 企业信用评级对企业的好处
  9. easyswoole初体验
  10. 给我深爱着的人,祝你中秋快乐……