OA项目操作步骤,带你一起办公

1.创建工程

1.1创建一个Maven的web工程

1.2在pom中修改编译器版本号

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>10</maven.compiler.source>
    <maven.compiler.target>10</maven.compiler.target>
  </properties>

1.3在pom中导入依赖

  • 依赖可以从maven中央仓库中获取

  • 在标签中添加spring版本号

    <spring.version>5.0.2.RELEASE</spring.version>
    形成如下形式

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>10</maven.compiler.source>
        <maven.compiler.target>10</maven.compiler.target>
        <spring.version>5.0.2.RELEASE</spring.version>
    </properties>
  • 再添加如下<dependencies/>标签
<dependencies>
        <!-- javax.servlet-api依赖 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
        <!-- javax.servlet.jsp-api依赖 -->
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.1</version>
            <scope>provided</scope>
        </dependency>
        <!-- jstl相关依赖 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.12</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.47</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jcl</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>
    </dependencies>

1.4在pom中注册资源目录

在pom文件的<build/>标签中添加如下内容

        <resources>
            <!--注册资源目录-->
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>

1.5完善Maven目录结构

创建src/main/java目录
创建src/main/resources目录
为目录添加相应的功能标签

1.6创建mybatis主配置文件
在src/main/resources目录中定义mybatis主配置文件

    <!--为实体类指定别名-->
    <typeAliases>
        <package name="cn.edu.aynu.bean"/>
    </typeAliases>

    <!--注册映射文件-->
    <mappers>
        <package name="cn.edu.aynu.dao"/>
    </mappers>

1.7创建Spring配置文件

在src/main/resources目录中定义spring配置文件

    <!--注册数据源-->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="url" value="jdbc:mysql:///test?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf8"/>
        <property name="username" value="root"/>
        <property name="password" value="12345678"/>
    </bean>

    <!--注册SqlSessionFactory-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="configLocation" value="classpath:mybatis.xml"/>
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <!--注册Dao-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="cn.edu.aynu.dao"/>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    </bean>

    <!--注册Service-->
    <context:component-scan base-package="cn.edu.aynu.service"/>

    <!--注册处理器-->
    <context:component-scan base-package="cn.edu.aynu.controller"/>

    <!--注册事务管理器-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <!--注册事务注解驱动-->
    <tx:annotation-driven transaction-manager="transactionManager"/>

1.8定义web.xml

  • 修改web.xml文件中遵循的servlet规范的版本,由默认的***2.3版本***修改为***3.1版本***
  • 在web.xml中写入如下内容
<!--注册字符编码过滤器-->
    <filter>
        <filter-name>characterEncoding</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>utf-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>characterEncoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!--注册中央调度器-->
    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>

1.9修改src/main/webapp中的内容

  • 删除maven工程中自带的***index.jsp***文件
  • 将项目原型内容复制到webapp目录

2.生成数据库

在***IntelliJ IDEA***中运行以下脚本

DROP DATABASE IF EXISTS oa;
CREATE DATABASE oa ;
USE oa ;

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `department`
-- ----------------------------
DROP TABLE IF EXISTS `department`;
CREATE TABLE `department` (
  `ID` int(11) NOT NULL,
  `depname` varchar(20) DEFAULT NULL,
  `pid` int(11) DEFAULT NULL,
  `email` varchar(30) DEFAULT NULL,
  `phone` varchar(20) DEFAULT NULL,
  `content` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of department
-- ----------------------------

-- ----------------------------
-- Table structure for `flow_manage`
-- ----------------------------
DROP TABLE IF EXISTS `flow_manage`;
CREATE TABLE `flow_manage` (
  `ID` int(11) NOT NULL,
  `uid` int(11) DEFAULT NULL,
  `flow_name` varchar(20) DEFAULT NULL,
  `flow_uid1` int(11) DEFAULT NULL,
  `assess1` char(1) DEFAULT NULL,
  `assess_time1` date DEFAULT NULL,
  `assess_view1` varchar(50) DEFAULT NULL,
  `flow_uid2` int(11) DEFAULT NULL,
  `assess2` char(1) DEFAULT NULL,
  `assess_view2` varchar(50) DEFAULT NULL,
  `assess_time2` date DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of flow_manage
-- ----------------------------

-- ----------------------------
-- Table structure for `meeting`
-- ----------------------------
DROP TABLE IF EXISTS `meeting`;
CREATE TABLE `meeting` (
  `ID` int(11) NOT NULL,
  `depid` int(11) DEFAULT NULL,
  `m_type` int(11) DEFAULT NULL,
  `m_name` varchar(20) DEFAULT NULL,
  `uid` int(11) DEFAULT NULL,
  `start_time` date DEFAULT NULL,
  `end_time` date DEFAULT NULL,
  `room_id` int(11) DEFAULT NULL,
  `all_uid` varchar(20) DEFAULT NULL,
  `content` varchar(100) DEFAULT NULL,
  `upload` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of meeting
-- ----------------------------

-- ----------------------------
-- Table structure for `meeting_room`
-- ----------------------------
DROP TABLE IF EXISTS `meeting_room`;
CREATE TABLE `meeting_room` (
  `ID` int(11) NOT NULL,
  `room_name` varchar(20) DEFAULT NULL,
  `room_content` varchar(100) DEFAULT NULL,
  `room_pic` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of meeting_room
-- ----------------------------

-- ----------------------------
-- Table structure for `meeting_type`
-- ----------------------------
DROP TABLE IF EXISTS `meeting_type`;
CREATE TABLE `meeting_type` (
  `ID` int(11) NOT NULL,
  `fid` int(11) DEFAULT NULL,
  `name` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of meeting_type
-- ----------------------------

-- ----------------------------
-- Table structure for `mess_group`
-- ----------------------------
DROP TABLE IF EXISTS `mess_group`;
CREATE TABLE `mess_group` (
  `ID` int(11) NOT NULL,
  `g_name` varchar(20) DEFAULT NULL,
  `g_content` varchar(50) DEFAULT NULL,
  `uid` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of mess_group
-- ----------------------------

-- ----------------------------
-- Table structure for `message`
-- ----------------------------
DROP TABLE IF EXISTS `message`;
CREATE TABLE `message` (
  `ID` int(11) NOT NULL,
  `g_id` int(11) DEFAULT NULL,
  `name` varchar(20) DEFAULT NULL,
  `sex` char(1) DEFAULT NULL,
  `phone` varchar(20) DEFAULT NULL,
  `MSN` varchar(20) DEFAULT NULL,
  `address` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of message
-- ----------------------------

-- ----------------------------
-- Table structure for `newlabel`
-- ----------------------------
DROP TABLE IF EXISTS `newlabel`;
CREATE TABLE `newlabel` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `label_name` varchar(20) DEFAULT NULL,
  `label_content` varchar(100) DEFAULT NULL,
  `pid` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of newlabel
-- ----------------------------
INSERT INTO `newlabel` VALUES ('1', '体育新闻', '体育新闻体育新闻体育新闻', null);
INSERT INTO `newlabel` VALUES ('2', '娱乐新闻', '娱乐新闻娱乐新闻娱乐新闻', null);
INSERT INTO `newlabel` VALUES ('3', '时政新闻', '时政新闻时政新闻时政新闻', null);
INSERT INTO `newlabel` VALUES ('4', '国际足球', '国际足球国际足球', '1');
INSERT INTO `newlabel` VALUES ('5', 'CBA', '中国篮球中国篮球', '1');
INSERT INTO `newlabel` VALUES ('6', '武林风', '河南武林风', '1');
INSERT INTO `newlabel` VALUES ('7', '网球', '网球网球', '1');
INSERT INTO `newlabel` VALUES ('8', '羽毛球', '羽毛球羽毛球', '1');
INSERT INTO `newlabel` VALUES ('9', '乒乓球', '乒乓球乒乓球', '1');
INSERT INTO `newlabel` VALUES ('10', '中超联赛', '中超联赛中超联赛', '1');
INSERT INTO `newlabel` VALUES ('11', '体坛名将', '体坛名将体坛名将', '1');
INSERT INTO `newlabel` VALUES ('12', '体坛快讯', '体坛快讯体坛快讯', '1');
INSERT INTO `newlabel` VALUES ('13', '内地影讯', '内地影讯内地影讯', '2');
INSERT INTO `newlabel` VALUES ('14', '内地影星', '内地影星内地影星', '2');
INSERT INTO `newlabel` VALUES ('15', '港台影星', '港台影星港台影星', '2');
INSERT INTO `newlabel` VALUES ('16', '欧美影讯', '欧美影讯欧美影讯', '2');
INSERT INTO `newlabel` VALUES ('17', '日韩影讯', '日韩影讯日韩影讯', '2');
INSERT INTO `newlabel` VALUES ('18', '今日历史', '今日历史今日历史', '3');
INSERT INTO `newlabel` VALUES ('19', '中央要闻', '中央要闻中央要闻', '3');
INSERT INTO `newlabel` VALUES ('20', '地方要闻', '地方要闻地方要闻', '3');
INSERT INTO `newlabel` VALUES ('21', '国际动态', '国际动态国际动态', '3');

-- ----------------------------
-- Table structure for `newmanage`
-- ----------------------------
DROP TABLE IF EXISTS `newmanage`;
CREATE TABLE `newmanage` (
  `ID` int(11) NOT NULL,
  `uid` int(11) DEFAULT NULL,
  `labelid` int(11) DEFAULT NULL,
  `title` varchar(20) DEFAULT NULL,
  `content` varchar(200) DEFAULT NULL,
  `time` date DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of newmanage
-- ----------------------------

-- ----------------------------
-- Table structure for `user_duty`
-- ----------------------------
DROP TABLE IF EXISTS `user_duty`;
CREATE TABLE `user_duty` (
  `ID` int(11) NOT NULL,
  `tid` int(11) DEFAULT NULL,
  `name` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of user_duty
-- ----------------------------

-- ----------------------------
-- Table structure for `users`
-- ----------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
  `ID` int(11) NOT NULL,
  `username` varchar(10) DEFAULT NULL,
  `password` varchar(10) DEFAULT NULL,
  `nickname` varchar(10) DEFAULT NULL,
  `worktime` date DEFAULT NULL,
  `sex` char(2) DEFAULT NULL,
  `depid` int(11) DEFAULT NULL,
  `duty` char(2) DEFAULT NULL,
  `email` varchar(20) DEFAULT NULL,
  `mobile` varchar(20) DEFAULT NULL,
  `homephone` varchar(20) DEFAULT NULL,
  `workphone` varchar(20) DEFAULT NULL,
  `fax` varchar(20) DEFAULT NULL,
  `MSN` varchar(20) DEFAULT NULL,
  `birthday` date DEFAULT NULL,
  `httpaddress` varchar(30) DEFAULT NULL,
  `address` varchar(100) DEFAULT NULL,
  `content` varchar(200) DEFAULT NULL,
  `logontime` date DEFAULT NULL,
  `lastlogontime` date DEFAULT NULL,
  `logoncount` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of users
-- ----------------------------

-- ----------------------------
-- Table structure for `work_help`
-- ----------------------------
DROP TABLE IF EXISTS `work_help`;
CREATE TABLE `work_help` (
  `ID` int(11) NOT NULL,
  `file` varchar(20) DEFAULT NULL,
  `content` varchar(50) DEFAULT NULL,
  `uid` int(11) DEFAULT NULL,
  `time` date DEFAULT NULL,
  `count` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of work_help
-- ----------------------------

-- ----------------------------
-- Table structure for `workmanage`
-- ----------------------------
DROP TABLE IF EXISTS `workmanage`;
CREATE TABLE `workmanage` (
  `ID` int(11) NOT NULL,
  `title` varchar(20) DEFAULT NULL,
  `content` varchar(300) DEFAULT NULL,
  `time` date DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of workmanage
-- ----------------------------

二、完成页面跳转

1.在web.xml中指定欢迎页面

    <welcome-file-list>
        <welcome-file>/html/login.htm</welcome-file>
    </welcome-file-list>

2.修改login.htm

  • 将文件扩展名***htm***修改为***jsp***

  • 在login页面中添加page指令

    <%@ page contentType=“text/html;charset=UTF-8” language=“java” %>

  • 修改web.xml中的欢迎页面扩展名

    <welcome-file-list>
        <welcome-file>/html/login.jsp</welcome-file>
    </welcome-file-list>
  • 将login页面中的***index.htm***修改为***index.jsp***
	if(name=="admin" && pwd=="admin")
	{	
		location.href="../html/index.jsp";
	  return true;
	}

3. 修改index.htm

  • 将***index.htm***的文件修改为***index.jsp***

4. 修改left.htm

  • 将html里的left.htm改成left.jsp

5. 修改栏目管理.htm

  • 将栏目管理.htm修改为***newslabelmanager.jsp***
<a href="news/newslablemanager.jsp" target="mainFrame" class="a03">栏目管理</a></td>

三、完成查询功能

  • 理解数据库中表里的数据之间的关系,找出一级菜单和二级菜单之间的 关系,从下表中发现父栏目和子栏目都在一张表中,区别于相联系的部分为pid 关联属性的为空时,也就是pid=null 时,则此时的栏目为一级栏目,当pid!=null 时,则此时为子栏目,在查询时查询一级栏目的子栏目信息时,可以通过自表相关联查询。实现一对多的查询。

*** 当数据库栏目表中的栏目名字后的pid为空时则此时栏目名称为以一级栏目,在接下来的查询中我们称为父栏目,pid不为空时,则称为子栏目***
在这里插入图片描述

  • 查询前要做的准备工作有以下几方面要做。

首先要定义好实体类,在bean下面建一个实体类名为***NewsLabel.java***
package bean;

import java.util.Set;

public class NewsLabel {
// 当前属性名与与数据库表中的名称不一致时,dao层时则选择resultmap
private Integer id;
private String name;
private String content;

// 关联属性:当前子栏目所隶属的父栏目
private NewsLabel parent;
// 关联属性:表示当前父栏目所包含的所有子栏目
private Set<NewsLabel> children;

}

  • 在dao 的实现类中要建的查询方法有以下几种
<!--通过ID查询-->
   【】dao层的方法,通过ID来查询表中的栏目信息 ,其中pid的值决定了该栏目
   是一级栏目还是二级栏目,pid的值为空时,此时栏目为一级栏目,当pid的值不为空时则 
   ,该栏目表示为子栏目,或二级栏目。所以此时应该使用动态查询。
   
  List<NewsLabel> selectNewsLabelsByPid(@Param("ppid") int pid);
   
   【】这是xml中的对应的SQL查询的方法
    <select id="selectNewsLabelsByPid" resultMap="NewslableMap">
        select id,label_name,label_content
        from newlabel
        <where>
            <choose>
              <when test="ppid=0">
                and pid is null
              </when>
              <otherwise>
                  and pid=#{pid}
              </otherwise>
            </choose>
        </where>
    </select>
    【】dao层中通过pid来查询表中共有多少条记录,pid的值有变动,所以使用动态的SQL
    查询
	  int selectTotalRowsByPid(@Param("ppid") int pid);
  
  【】xml中所对应的SQL查询语句
  	<select id="selectTotalRowsByPid" resultType="int">
      select count(id) from newlabel
      <if test="ppid!=0">
          where pid=#{pid}
      </if>
    </select>
【】dao层中的查询当前页面的中父栏目的子栏目,和当前显示的页面大小和记录的条数
    Set<NewsLabel> selectCurrentPageNewsLabel(Map<String, Integer> map);
   
   【】xml中对应的SQL的查询语句,limi 是SQL提供的页面查询方法
    <select id="selectCurrentPageNewsLabel" resultMap="Newslableparent">
        select id,label_name,label_content
        from newlabel
        limit  #{pageStartIndex},#{pageSize}
    </select>
  • 对于查询当前页面展示的记录条数和页码数,此时提供源码和解析如下
    1.首先要建立page这个类,并进行对当前页面所需要的数据进行 定义

import lombok.Data;

import java.util.Set;

/**
 * bean: 实体类,一般具有id属性,且与DB中的某张表具有对应关系
 * entity: 造价于bean
 * po: persistant object,持久化对象,造价于bean
 *
 * vo: value object,值对象,一般不具有id属性,且与DB中的表不具有对应关系,
 *     其一般用于在页面与类间传递数据
 * dto: data transfer object,数据传输对象,一般不具有id属性,且与DB中的表不具有对应关系,
 *     其一般用于在类间传递数据
 *
 * 这是一个vo类
 * company: www.abc.com
 * Author: Administrator
 * Create Data: 2018/11/21 0021
【】 *其中的 T 是给定泛型的所有,每个页面所显示的数据和需要都不一样的而需求,所以
 会变化,定义在类上的泛型,可以根据需求而改变
 */
@Data
public class Page<T> {
    /**
     * 页码(给定)
     */
    private int pageno;
    /**
     * 页面大小(给定)
     */
    private int pageSize;
    /**
     * 当前页的起始索引(可通过计算出当前页码的索引,索引从零开始)
     */
    private int pageStartIndex;
    /**
     * 总记录数(查询)
     */
    private int totalRows;
    /**
     * 总页数,最后一页的页码(可通过计算获得)
     */
    private int totalPages;
    /**
     * 当前页所包含的数据详情(查询)
     */
    private Set<T> datas;

    public Page() {
        this.pageno = 1;
        this.pageSize = 3;
    }
【】当页面显示有变化时提供的有参构造方法
    public Page(int pageno, int pageSize) {
        if(pageno <= 0) {
            pageno = 1;
        }
        if(pageSize <= 0) {
            pageSize = 3;
        }
        this.pageno = pageno;
        this.pageSize = pageSize;
    }
【】计算当前页面开始时的索引

    public int getPageStartIndex() {
        return (pageno -1) * pageSize;
    }

【】计算总的 页数
    public int getTotalPages() {
        totalPages = totalRows / pageSize;
        if(totalRows % pageSize != 0) {
            totalPages++;
        }
        return totalPages;
    }
}

2.建立当前页面的方法,直接了解service实现类里的方法吧,接口中的方法,都是一样的。

public Page findCurrentPage() {
        Page<NewsLabel> page = new Page<>();

        int totalRows = dao.selectTotalRowsByPid(0);
        page.setTotalRows(totalRows);

        Map<String, Integer> map = new HashMap<>();
        map.put("pageStartIndex", page.getPageStartIndex());
        map.put("pageSize", page.getPageSize());
        Set<NewsLabel> datas = dao.selectCurrentPageNewsLabel(map);
        page.setDatas(datas);
        return page;
    }



四、完成删除功能

五、完成修改功能

六、完成插入功能

猜你喜欢

转载自blog.csdn.net/qq_40674814/article/details/84237847