程序笔记   发布时间:2022-07-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了SSM动态展示分页大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这个作业属于哪个课程 2021春软件工程实践|S班(福州大学)
这个作业要求在哪里 作业具体要求
这个作业的目标 个人技术
文献 ...

目录
  • 技术概述
  • 技术详述
  • 问题和解决过程
  • 总结
  • 文献

技术概述

SSM的分页技术主要在我负责的产品的中在信息展示时会使用到,分别在讨论和签到的多页展示中,由于数据库的内容可能会比较多,为了减少查询的压力和前端的美化,在摒弃无线下拉的情况下,所以需要使用该技术,难点主要存在于和前后端对接的具体数据接口可能会出现无法对接问题

技术详述

  • 1.首先在pom中配置需要的pageHelper的依赖
    <dependency>
      <groupId>com.github.pageHelper</groupId>
      <artifactId>pageHelper</artifactId>
      <version>5.2.0</version>
    </dependency>
  • 2.在Controller列表展示页面加入一个有当前页面参数的Integer currentPage
    @requestMapping("/detail")
    @ResponseBody
    public Topic getCommentList(Integer id,@requestParam(value = "currentPage",required=false,DefaultValue="1")Integer currentPagE){
        Topic topic=topicservice.findTopicComment(id,currentPagE);
        return topic;
    }
  • 3.在实现了service接口的serviceImpl函数中调用pageHelper,并传入具体参数
public class TopicController {
    @Autowired
    private Topicservice topicservice;
    @requestMapping("/category")
    /**
     *
     * 搜索
     */
    @ResponseBody
    public List<Topic> getCategory(String content,String type,Model model,@requestParam(value = "currentPage",required=false,DefaultValue="1")Integer currentPagE){
        List<Topic> topics=null;
        if(type.equals("title")) {
            topics=topicservice.findTopicBytitle(content,currentPagE);
        }
        else{
            topics=topicservice.findTopicByAccount(content,currentPagE);
        }
        model.addAttribute(topics);
        return topics;
    }
    @requestMapping("/all")
    @ResponseBody
    public List<Topic> getAll(@requestParam(value = "currentPage",required=false,DefaultValue="1")Integer currentPagE){
        List<Topic> topics=topicservice.findAllTopic(currentPagE);
        return topics;
    }
    @requestMapping("/detail")
    @ResponseBody
    public Topic getCommentList(Integer id,@requestParam(value = "currentPage",required=false,DefaultValue="1")Integer currentPagE){
        Topic topic=topicservice.findTopicComment(id,currentPagE);
        return topic;
    }
    @requestMapping("/newTopic")
    @ResponseBody
    public int insertTopic(Topic topiC){
        int rows=topicservice.insertTopic(topic);
        return rows;
    }
    @requestMapping("/deleteTopic")
    @ResponseBody
    public int deleteTopic(Integer id){
        int rows=topicservice.deleteTopic(id);
        return rows;
    }
}
  • 4.当然,在具体的Mapper中还要编写相应的和数据库的查询操作,这和未加分页的方法是一样的,这里就举几个例子
<mapper namespace="team.ljm.secw.mapper.TopicMapper">

    <SELEct id="findTopicById" parameterType="Integer" resultType="Topic">
        SELEct * FROM t_topic where id = #{iD}
    </SELEct>
    <SELEct id="findTopicBytitle" parameterType="String" resultType="Topic">
        SELEct * FROM t_topic where title=#{titlE}
    </SELEct>
    <SELEct id="findTopicByAccount" parameterType="String" resultType="Topic">
        SELEct * FROM t_topic where account=#{account}
    </SELEct>
  • 5.流程图

    SSM动态展示分页

问题和解决过程

  • 分页的问题其实是在具体底层mybatis的查询功能都做完之后才开始编写虑的,主要的原因是在摒弃无限下拉的展示功能后,虑到内容展示需要在每个页面有一定的限制,所以选择了比较好用的pageHelper来快速实现分页功能,在后端测试时,使用了一点点的jsp代码来进行测试
<div class="page text-left clearfix" style="margin-top: 40px">
    <a <c:if test="${pageInfo.pageNum != 1}">href="${pageContext.request.contextPath}/product/list?currentPage=${pageInfo.pageNum - 1 }"</c:if>
            <c:if test="${pageInfo.pageNum == 1}"> href="javascript:void(0)" class="disabled"</c:if>
    >上一页</a>
    <c:forEach begin="1" end="${pageInfo.pages }" varStatus="status">
        <a href="${pageContext.request.contextPath}/product/list?currentPage=${status.count }"
           <c:if test="${status.count == pageInfo.pageNum}">class="SELEct"</c:if>>${status.count }</a>
    </c:forEach>

    <a <c:if test="${pageInfo.pageNum == 20}">class="disabled" href="javascript:void(0)"</c:if>
       <c:if test="${pageInfo.pageNum != 20}">href="${pageContext.request.contextPath}/product/list?currentPage=${pageInfo.pageNum + 1 }"</c:if>
    >下一页</a>
</div>

最终结果也是比较喜人的,算是顺利解决

总结

pageHelper属于对于前端界面的一个补充和对数据库查询的压力降低,网上对这方面的使用教程应该也挺多的,但和自己实际操作起来还是很不一样,总体来说前后的pageHelper的使用算是比较顺利,测试也很快,我相信SSM还有很多很好用的插件等着自己去探索,这次的SSM框架使用中,发现了很多之前没虑到的做软件需要的部分,比如安全性检查,防止恶意入侵等,对于构建项目的整体认识感到新的一番体验

文献

PageHelper的概述和基本使用--冰块儿+奶茶

大佬总结

以上是大佬教程为你收集整理的SSM动态展示分页全部内容,希望文章能够帮你解决SSM动态展示分页所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。