• javaee ssm框架项目添加分页控件


    在这里插入图片描述

    搭建ssm框架项目

    参考上一篇博文

    添加分页控件

    引入依赖

    
    
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0modelVersion>
    
      <groupId>org.examplegroupId>
      <artifactId>testSSM2artifactId>
      <version>1.0-SNAPSHOTversion>
      <packaging>warpackaging>
    
      <name>testSSM2 Maven Webappname>
      
      <url>http://www.example.comurl>
    
      <properties>
        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
        <maven.compiler.source>1.7maven.compiler.source>
        <maven.compiler.target>1.7maven.compiler.target>
      properties>
    
      <dependencies>
        <dependency>
          <groupId>junitgroupId>
          <artifactId>junitartifactId>
          <version>4.11version>
          <scope>testscope>
        dependency>
    
        
        <dependency>
          <groupId>org.springframeworkgroupId>
          <artifactId>spring-contextartifactId>
          <version>4.3.18.RELEASEversion>
        dependency>
        <dependency>
          <groupId>org.springframeworkgroupId>
          <artifactId>spring-coreartifactId>
          <version>4.3.18.RELEASEversion>
        dependency>
    
        <dependency>
          <groupId>org.springframeworkgroupId>
          <artifactId>spring-beansartifactId>
          <version>4.3.18.RELEASEversion>
        dependency>
        <dependency>
          <groupId>org.springframeworkgroupId>
          <artifactId>spring-context-supportartifactId>
          <version>4.3.18.RELEASEversion>
        dependency>
    
        
        <dependency>
          <groupId>mysqlgroupId>
          <artifactId>mysql-connector-javaartifactId>
          <version>5.1.37version>
        dependency>
        <dependency>
          <groupId>org.mybatisgroupId>
          <artifactId>mybatisartifactId>
          <version>3.4.6version>
        dependency>
        <dependency>
          <groupId>com.mchangegroupId>
          <artifactId>c3p0artifactId>
          <version>0.9.5.2version>
        dependency>
    
        
        <dependency>
          <groupId>log4jgroupId>
          <artifactId>log4jartifactId>
          <version>1.2.17version>
        dependency>
    
        
        <dependency>
          <groupId>org.mybatisgroupId>
          <artifactId>mybatis-springartifactId>
          <version>1.3.0version>
        dependency>
        <dependency>
          <groupId>org.springframeworkgroupId>
          <artifactId>spring-jdbcartifactId>
          <version>4.3.18.RELEASEversion>
        dependency>
        
        <dependency>
          <groupId>org.springframeworkgroupId>
          <artifactId>spring-webmvcartifactId>
          <version>4.3.18.RELEASEversion>
        dependency>
        <dependency>
          <groupId>org.springframeworkgroupId>
          <artifactId>spring-webartifactId>
          <version>4.3.18.RELEASEversion>
        dependency>
    
        
        <dependency>
          <groupId>javax.servletgroupId>
          <artifactId>jstlartifactId>
          <version>1.2version>
        dependency>
    
        
        <dependency>
          <groupId>com.github.pagehelpergroupId>
          <artifactId>pagehelperartifactId>
          <version>5.1.2version>
        dependency>
    
        
        
        <dependency>
          <groupId>javax.servletgroupId>
          <artifactId>javax.servlet-apiartifactId>
          <version>3.1.0version>
          <scope>providedscope>
        dependency>
    
        
        <dependency>
          <groupId>javax.servlet.jspgroupId>
          <artifactId>jsp-apiartifactId>
          <version>2.2version>
          <scope>providedscope>
        dependency>
      dependencies>
    
      <build>
        <resources>
          <resource>
            
            <directory>src/main/javadirectory>
            <includes>
              <include>**/*.xmlinclude>
            includes>
            <filtering>truefiltering>
          resource>
        resources>
        <finalName>testSSM2finalName>
        <pluginManagement>
          <plugins>
            <plugin>
              <artifactId>maven-clean-pluginartifactId>
              <version>3.1.0version>
            plugin>
            
            <plugin>
              <artifactId>maven-resources-pluginartifactId>
              <version>3.0.2version>
            plugin>
            <plugin>
              <artifactId>maven-compiler-pluginartifactId>
              <version>3.8.0version>
            plugin>
            <plugin>
              <artifactId>maven-surefire-pluginartifactId>
              <version>2.22.1version>
            plugin>
            <plugin>
              <artifactId>maven-war-pluginartifactId>
              <version>3.2.2version>
            plugin>
            <plugin>
              <artifactId>maven-install-pluginartifactId>
              <version>2.5.2version>
            plugin>
            <plugin>
              <artifactId>maven-deploy-pluginartifactId>
              <version>2.8.2version>
            plugin>
          plugins>
        pluginManagement>
      build>
    project>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179

    修改mybatis配置文件

    
    DOCTYPE configuration
            PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
            "http://mybatis.org/dtd/mybatis-3-config.dtd">
    <configuration>
    
        
        
        
        <settings>
            <setting name="logImpl" value="STDOUT_LOGGING"/>
        settings>
    
        
        <typeAliases>
            <package name="com.test.pojo" />
        typeAliases>
    
        
        
            
                
                
                    
                    
                    
                    
                
            
        
    
         
        
           
        
    
        
        <plugins>
            <plugin interceptor="com.github.pagehelper.PageInterceptor" />
        plugins>
    
    configuration>   
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42

    测试

    package com.test.controller;
    
    import com.github.pagehelper.PageInfo;
    import com.test.pojo.Items;
    import com.test.service.IItemsService;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.servlet.ModelAndView;
    
    import java.util.List;
    
    @Controller
    @RequestMapping("/items")
    public class ItemsController {
    
        @Autowired
        private IItemsService itemsService;
    
        public IItemsService getItemsService() {
            return itemsService;
        }
    
        public void setItemsService(IItemsService itemsService) {
            this.itemsService = itemsService;
        }
    
        @RequestMapping("/selectAllItems")
        public ModelAndView selectAllItems()
        {
    
            List<Items> itemsList= itemsService.selectItems();
    
            // System.out.println(itemsList);
    
            ModelAndView modelAndView=new ModelAndView();
    
            modelAndView.addObject("itemsList",itemsList);
    
            modelAndView.setViewName("showItems");
    
            return modelAndView;
        }
    
        @RequestMapping("/selectAllItemsByPage")
        public ModelAndView selectAllItemsByPage(@RequestParam(value ="pageindex",defaultValue = "1") int pageindex)
        {
            PageInfo<Items> pageInfo= itemsService.selectItemsByPage(pageindex,2);
    
            ModelAndView modelAndView=new ModelAndView();
    
            modelAndView.addObject("pageInfo",pageInfo);
    
            modelAndView.setViewName("showItemsByPage");
    
            return modelAndView;
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    package com.test.service;
    
    import com.github.pagehelper.PageInfo;
    import com.test.pojo.Items;
    
    import java.util.List;
    
    public interface IItemsService {
    
        public List<Items> selectItems();
    
        public PageInfo<Items> selectItemsByPage(int pageindex, int pagesize);
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    package com.test.service.impl;
    
    import com.github.pagehelper.PageHelper;
    import com.github.pagehelper.PageInfo;
    import com.test.mapper.ItemsMapper;
    import com.test.pojo.Items;
    import com.test.service.IItemsService;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    
    import java.util.List;
    
    @Service
    public class ItemsService implements IItemsService {
    
        @Autowired
        private ItemsMapper itemsMapper;
    
        public ItemsMapper getItemsMapper() {
            return itemsMapper;
        }
    
        public void setItemsMapper(ItemsMapper itemsMapper) {
            this.itemsMapper = itemsMapper;
        }
    
        //查询所有
        @Override
        public List<Items> selectItems() {
    
            return itemsMapper.selectItems();
        }
    
        //分页查询
        public PageInfo<Items> selectItemsByPage(int pageindex,int pagesize)
        {
            //1.开启分页
            PageHelper.startPage(pageindex,pagesize);
            //2.查询
            List<Items> itemsList= itemsMapper.selectItems();
            //3.组装PageInfo对象 返回
            PageInfo<Items> pageInfo=new PageInfo<Items>(itemsList);
    
            return pageInfo;
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%
       String baseUrl=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath();
    
       pageContext.setAttribute("baseUrl",baseUrl);
    %>
    <html>
    <head >
        <base href="${baseUrl}">
        <title>Titletitle>
    head>
    <body>
     <c:forEach var="items" items="${pageInfo.list}">
           ${items.name}<br/>
     c:forEach>
    
    <c:forEach var="i" begin="1" end="${pageInfo.pages}">
       <a href="${baseUrl}/items/selectAllItemsByPage?pageindex=${i}">${i}a>
    c:forEach>
    body>
    html>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
  • 相关阅读:
    全网最全Redis学习
    【3D建模制作技巧分享】Maya模型如何导入zbrush
    vue的两种服务器端渲染方案
    数据结构 图
    新冠疫情历史数据可视化分析
    php学习总结
    GrennPlum存储过程实战
    大型园区网络建设与管理-网络管理7.1
    Chow-Liu Tree
    redis 发布者订阅者实例
  • 原文地址:https://blog.csdn.net/Rockandrollman/article/details/133588949