码迷,mamicode.com
首页 > 编程语言 > 详细

SpringBoot 分页处理

时间:2018-11-06 13:26:09      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:serve   col   flag   打包   技术   nal   val   edit   git   

开始主要是要使用已经设计好的数据库

-- ----------------------------------------------------
--  用户
-- ----------------------------------------------------
--  Table structure for `sys_user`
-- ----------------------------------------------------
CREATE TABLE `sys_user` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT 编号,
  `name` varchar(50) NOT NULL COMMENT 用户名,
  `password` varchar(100) COMMENT 密码,
  `salt` varchar(40) COMMENT ,
  `email` varchar(100) COMMENT 邮箱,
  `mobile` varchar(100) COMMENT 手机号,
  `status` tinyint COMMENT 状态  0:禁用   1:正常,
  `dept_id` bigint(20) COMMENT 机构ID,
  `create_by` varchar(50) COMMENT 创建人,
  `create_time` datetime COMMENT 创建时间,
  `last_update_by` varchar(50) COMMENT 更新人,
  `last_update_time` datetime COMMENT 更新时间,
  `del_flag` tinyint DEFAULT 0 COMMENT 是否删除  -1:已删除  0:正常,
  PRIMARY KEY (`id`),
  UNIQUE INDEX (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=用户;

-- ----------------------------------------------------
--  机构
-- ------------------------------------------------
--  Table structure for `sys_dept`
-- ------------------------------------------------
CREATE TABLE `sys_dept` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT 编号,
  `name` varchar(50) COMMENT 机构名称,
  `parent_id` bigint COMMENT 上级机构ID,一级机构为0,
  `order_num` int COMMENT 排序,
  `create_by` varchar(50) COMMENT 创建人,
  `create_time` datetime COMMENT 创建时间,
  `last_update_by` varchar(50) COMMENT 更新人,
  `last_update_time` datetime COMMENT 更新时间,
  `del_flag` tinyint DEFAULT 0 COMMENT 是否删除  -1:已删除  0:正常,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=机构管理;

-- ------------------------------------------------
--  角色
-- ------------------------------------------------
--  Table structure for `sys_role`
-- ------------------------------------------------
CREATE TABLE `sys_role` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT 编号,
  `name` varchar(100) COMMENT 角色名称,
  `remark` varchar(100) COMMENT 备注,
  `create_by` varchar(50) COMMENT 创建人,
  `create_time` datetime COMMENT 创建时间,
  `last_update_by` varchar(50) COMMENT 更新人,
  `last_update_time` datetime COMMENT 更新时间,
  `del_flag` tinyint DEFAULT 0 COMMENT 是否删除  -1:已删除  0:正常,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=角色;

-- ------------------------------------------------
--  菜单
-- ------------------------------------------------
--  Table structure for `sys_menu`
-- ------------------------------------------------
CREATE TABLE `sys_menu` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT 编号,
  `name` varchar(50) COMMENT 菜单名称,
  `parent_id` bigint COMMENT 父菜单ID,一级菜单为0,
  `url` varchar(200) COMMENT 菜单URL,
  `perms` varchar(500) COMMENT 授权(多个用逗号分隔,如:user:view,user:create),
  `type` int COMMENT 类型   0:目录   1:菜单   2:按钮,
  `icon` varchar(50) COMMENT 菜单图标,
  `order_num` int COMMENT 排序,
  `create_by` varchar(50) COMMENT 创建人,
  `create_time` datetime COMMENT 创建时间,
  `last_update_by` varchar(50) COMMENT 更新人,
  `last_update_time` datetime COMMENT 更新时间,
  `del_flag` tinyint DEFAULT 0 COMMENT 是否删除  -1:已删除  0:正常,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=菜单管理;

-- ------------------------------------------------
--  用户与角色对应关系
-- ------------------------------------------------
--  Table structure for `sys_user_role`
-- ------------------------------------------------
CREATE TABLE `sys_user_role` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT 编号,
  `user_id` bigint COMMENT 用户ID,
  `role_id` bigint COMMENT 角色ID,
  `create_by` varchar(50) COMMENT 创建人,
  `create_time` datetime COMMENT 创建时间,
  `last_update_by` varchar(50) COMMENT 更新人,
  `last_update_time` datetime COMMENT 更新时间,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=用户与角色对应关系;

-- ------------------------------------------------
--  角色与机构对应关系
-- ------------------------------------------------
--  Table structure for `sys_role_dept`
-- ------------------------------------------------
CREATE TABLE `sys_role_dept` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT 编号,
  `role_id` bigint COMMENT 角色ID,
  `dept_id` bigint COMMENT 机构ID,
  `create_by` varchar(50) COMMENT 创建人,
  `create_time` datetime COMMENT 创建时间,
  `last_update_by` varchar(50) COMMENT 更新人,
  `last_update_time` datetime COMMENT 更新时间,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=角色与机构对应关系;

-- ------------------------------------------------
--  角色与菜单对应关系
-- ------------------------------------------------
--  Table structure for `sys_role_menu`
-- ------------------------------------------------
CREATE TABLE `sys_role_menu` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT 编号,
  `role_id` bigint COMMENT 角色ID,
  `menu_id` bigint COMMENT 菜单ID,
  `create_by` varchar(50) COMMENT 创建人,
  `create_time` datetime COMMENT 创建时间,
  `last_update_by` varchar(50) COMMENT 更新人,
  `last_update_time` datetime COMMENT 更新时间,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=角色与菜单对应关系;

-- ------------------------------------------------
--  用户Token
-- ------------------------------------------------
--  Table structure for `sys_user_token`
-- ------------------------------------------------
CREATE TABLE `sys_user_token` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT 编号,
  `user_id` bigint NOT NULL,
  `token` varchar(100) NOT NULL COMMENT token,
  `expire_time` datetime DEFAULT NULL COMMENT 过期时间,
  `create_by` varchar(50) COMMENT 创建人,
  `create_time` datetime COMMENT 创建时间,
  `last_update_by` varchar(50) COMMENT 更新人,
  `last_update_time` datetime COMMENT 更新时间,
  PRIMARY KEY (`id`),
  UNIQUE KEY `token` (`token`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=用户Token;

-- ------------------------------------------------
--  系统日志
-- ------------------------------------------------
--  Table structure for `sys_log`
-- ------------------------------------------------
CREATE TABLE `sys_log` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT 编号,
  `user_name` varchar(50) COMMENT 用户名,
  `operation` varchar(50) COMMENT 用户操作,
  `method` varchar(200) COMMENT 请求方法,
  `params` varchar(5000) COMMENT 请求参数,
  `time` bigint NOT NULL COMMENT 执行时长(毫秒),
  `ip` varchar(64) COMMENT IP地址,
  `create_by` varchar(50) COMMENT 创建人,
  `create_time` datetime COMMENT 创建时间,
  `last_update_by` varchar(50) COMMENT 更新人,
  `last_update_time` datetime COMMENT 更新时间,
  PRIMARY KEY (`id`)
) ENGINE=`InnoDB` DEFAULT CHARACTER SET utf8 COMMENT=系统日志;

-- ------------------------------------------------
--  数据字典
-- ------------------------------------------------
--  Table structure for `sys_dict`
-- ------------------------------------------------
DROP TABLE IF EXISTS `sys_dict`;
CREATE TABLE `sys_dict` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT 编号,
  `value` varchar(100) NOT NULL COMMENT 数据值,
  `label` varchar(100) NOT NULL COMMENT 标签名,
  `type` varchar(100) NOT NULL COMMENT 类型,
  `description` varchar(100) NOT NULL COMMENT 描述,
  `sort` decimal(10,0) NOT NULL COMMENT 排序(升序),
  `create_by` varchar(50) COMMENT 创建人,
  `create_time` datetime COMMENT 创建时间,
  `last_update_by` varchar(50) COMMENT 更新人,
  `last_update_time` datetime COMMENT 更新时间,
  `remarks` varchar(255) DEFAULT NULL COMMENT 备注信息,
  `del_flag` tinyint DEFAULT 0 COMMENT 是否删除  -1:已删除  0:正常,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=字典表;

-- --------------------------------------
-- 初始数据
-- --------------------------------------
--  Records of `sys_user`
-- --------------------------------------
INSERT INTO `sys_user` (`id`, `name`, `password`, `salt`, `dept_id`, `email`, `mobile`, `status`, `create_time`) VALUES (1, admin, 9ec9750e709431dad22365cabc5c625482e574c74adaebba7dd02f1129e4ce1d, YzcmCZNvbXocrsz9dm8e, 4, admin@qq.com, 13612345678, 1, 2018-08-14 11:11:11);
INSERT INTO `sys_user` (`id`, `name`, `password`, `salt`, `dept_id`, `email`, `mobile`, `status`, `create_time`) VALUES (2, Louis, 9ec9750e709431dad22365cabc5c625482e574c74adaebba7dd02f1129e4ce1d, YzcmCZNvbXocrsz9dm8e, 6, louis@qq.com, 18200932238, 1, 2018-08-14 11:11:11);
INSERT INTO `sys_user` (`id`, `name`, `password`, `salt`, `dept_id`, `email`, `mobile`, `status`, `create_time`) VALUES (3, Kobe, 9ec9750e709431dad22365cabc5c625482e574c74adaebba7dd02f1129e4ce1d, YzcmCZNvbXocrsz9dm8e, 7, kobe@qq.com, 18200932238, 1, 2018-08-14 11:11:11);
INSERT INTO `sys_user` (`id`, `name`, `password`, `salt`, `dept_id`, `email`, `mobile`, `status`, `create_time`) VALUES (4, Iverson, 9ec9750e709431dad22365cabc5c625482e574c74adaebba7dd02f1129e4ce1d, YzcmCZNvbXocrsz9dm8e, 8, iverson@qq.com, 18200932238, 1, 2018-08-14 11:11:11);
INSERT INTO `sys_user` (`id`, `name`, `password`, `salt`, `dept_id`, `email`, `mobile`, `status`, `create_time`) VALUES (5, Iverson5, 9ec9750e709431dad22365cabc5c625482e574c74adaebba7dd02f1129e4ce1d, YzcmCZNvbXocrsz9dm8e, 12, iverson@qq.com, 18200932238, 1, 2018-08-14 11:11:11);
INSERT INTO `sys_user` (`id`, `name`, `password`, `salt`, `dept_id`, `email`, `mobile`, `status`, `create_time`) VALUES (6, Iverson6, 9ec9750e709431dad22365cabc5c625482e574c74adaebba7dd02f1129e4ce1d, YzcmCZNvbXocrsz9dm8e, 12, iverson@qq.com, 18200932238, 1, 2018-08-14 11:11:11);
INSERT INTO `sys_user` (`id`, `name`, `password`, `salt`, `dept_id`, `email`, `mobile`, `status`, `create_time`) VALUES (7, Iverson7, 9ec9750e709431dad22365cabc5c625482e574c74adaebba7dd02f1129e4ce1d, YzcmCZNvbXocrsz9dm8e, 13, iverson@qq.com, 18200932238, 1, 2018-08-14 11:11:11);
INSERT INTO `sys_user` (`id`, `name`, `password`, `salt`, `dept_id`, `email`, `mobile`, `status`, `create_time`) VALUES (8, Iverson8, 9ec9750e709431dad22365cabc5c625482e574c74adaebba7dd02f1129e4ce1d, YzcmCZNvbXocrsz9dm8e, 14, iverson@qq.com, 18200932238, 1, 2018-08-14 11:11:11);
INSERT INTO `sys_user` (`id`, `name`, `password`, `salt`, `dept_id`, `email`, `mobile`, `status`, `create_time`) VALUES (9, Iverson9, 9ec9750e709431dad22365cabc5c625482e574c74adaebba7dd02f1129e4ce1d, YzcmCZNvbXocrsz9dm8e, 15, iverson@qq.com, 18200932238, 1, 2018-08-14 11:11:11);
INSERT INTO `sys_user` (`id`, `name`, `password`, `salt`, `dept_id`, `email`, `mobile`, `status`, `create_time`) VALUES (10, Iverson10, 9ec9750e709431dad22365cabc5c625482e574c74adaebba7dd02f1129e4ce1d, YzcmCZNvbXocrsz9dm8e, 4, iverson@qq.com, 18200932238, 1, 2018-08-14 11:11:11);
INSERT INTO `sys_user` (`id`, `name`, `password`, `salt`, `dept_id`, `email`, `mobile`, `status`, `create_time`) VALUES (11, Iverson11, 9ec9750e709431dad22365cabc5c625482e574c74adaebba7dd02f1129e4ce1d, YzcmCZNvbXocrsz9dm8e, 6, iverson@qq.com, 18200932238, 1, 2018-08-14 11:11:11);
INSERT INTO `sys_user` (`id`, `name`, `password`, `salt`, `dept_id`, `email`, `mobile`, `status`, `create_time`) VALUES (12, Iverson12, 9ec9750e709431dad22365cabc5c625482e574c74adaebba7dd02f1129e4ce1d, YzcmCZNvbXocrsz9dm8e, 15, iverson@qq.com, 18200932238, 1, 2018-08-14 11:11:11);
-- --------------------------------------
--  Records of `sys_role`
-- --------------------------------------
INSERT INTO `sys_role` (`id`, `name`, `remark`, `create_time`) VALUES (1, admin, 超级管理员, 2018-08-14 11:11:11);
INSERT INTO `sys_role` (`id`, `name`, `remark`, `create_time`) VALUES (2, dev, 开发人员, 2018-08-14 11:11:11);
INSERT INTO `sys_role` (`id`, `name`, `remark`, `create_time`) VALUES (3, test, 测试人员, 2018-08-14 11:11:11);
-- --------------------------------------
--  Records of `sys_user_role`
-- --------------------------------------
INSERT INTO `sys_user_role` (`id`, `user_id`, `role_id`) VALUES (1, 1, 1);
INSERT INTO `sys_user_role` (`id`, `user_id`, `role_id`) VALUES (2, 2, 1);
INSERT INTO `sys_user_role` (`id`, `user_id`, `role_id`) VALUES (3, 3, 2);
INSERT INTO `sys_user_role` (`id`, `user_id`, `role_id`) VALUES (4, 4, 3);
-- --------------------------------------
--  Records of `sys_dept`
-- --------------------------------------
INSERT INTO `sys_dept` (`id`, `parent_id`, `name`, `order_num`, `del_flag`) VALUES (1, 0, 轻尘集团, 0, 0);
INSERT INTO `sys_dept` (`id`, `parent_id`, `name`, `order_num`, `del_flag`) VALUES (2, 1, 北京分公司, 1, 0);
INSERT INTO `sys_dept` (`id`, `parent_id`, `name`, `order_num`, `del_flag`) VALUES (3, 1, 上海分公司, 2, 0);
INSERT INTO `sys_dept` (`id`, `parent_id`, `name`, `order_num`, `del_flag`) VALUES (4, 3, 技术部, 0, 0);
INSERT INTO `sys_dept` (`id`, `parent_id`, `name`, `order_num`, `del_flag`) VALUES (6, 3, 宣传部, 1, 0);
INSERT INTO `sys_dept` (`id`, `parent_id`, `name`, `order_num`, `del_flag`) VALUES (7, 3, 销售部, 2, 0);
INSERT INTO `sys_dept` (`id`, `parent_id`, `name`, `order_num`, `del_flag`) VALUES (8, 3, 市场部, 3, 0);
INSERT INTO `sys_dept` (`id`, `parent_id`, `name`, `order_num`, `del_flag`) VALUES (9, 0, 牧尘集团, 1, 0);
INSERT INTO `sys_dept` (`id`, `parent_id`, `name`, `order_num`, `del_flag`) VALUES (10, 9, 北京分公司, 1, 0);
INSERT INTO `sys_dept` (`id`, `parent_id`, `name`, `order_num`, `del_flag`) VALUES (11, 9, 上海分公司, 2, 0);
INSERT INTO `sys_dept` (`id`, `parent_id`, `name`, `order_num`, `del_flag`) VALUES (12, 10, 技术部, 1, 0);
INSERT INTO `sys_dept` (`id`, `parent_id`, `name`, `order_num`, `del_flag`) VALUES (13, 10, 宣传部, 2, 0);
INSERT INTO `sys_dept` (`id`, `parent_id`, `name`, `order_num`, `del_flag`) VALUES (14, 11, 销售部, 1, 0);
INSERT INTO `sys_dept` (`id`, `parent_id`, `name`, `order_num`, `del_flag`) VALUES (15, 11, 市场部, 2, 0);
-- --------------------------------------
--  Records of `sys_menu`
-- --------------------------------------
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (1, 0, 系统管理, NULL, NULL, 0, fa el-icon-setting, 0);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (2, 1, 用户管理, /sys/user, NULL, 1, el-icon-service, 1);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (3, 1, 机构管理, /sys/dept, NULL, 1, el-icon-news, 2);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (4, 1, 角色管理, /sys/role, NULL, 1, el-icon-view, 4);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (5, 1, 菜单管理, /sys/menu, NULL, 1, el-icon-menu, 5);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (6, 1, SQL监控, /druid/sql, NULL, 1, el-icon-info, 6);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (8, 1, 系统日志, /sys/log, sys:log:view, 1, el-icon-info, 7);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (9, 2, 查看, NULL, sys:user:view, 2, NULL, 0);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (10, 2, 新增, NULL, sys:user:add, 2, NULL, 0);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (11, 2, 修改, NULL, sys:user:edit, 2, NULL, 0);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (12, 2, 删除, NULL, sys:user:delete, 2, NULL, 0);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (13, 3, 查看, NULL, sys:dept:view, 2, NULL, 0);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (14, 3, 新增, NULL, sys:dept:add, 2, NULL, 0);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (15, 3, 修改, NULL, sys:dept:edit, 2, NULL, 0);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (16, 3, 删除, NULL, sys:dept:delete, 2, NULL, 0);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (17, 4, 查看, NULL, sys:role:view, 2, NULL, 0);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (18, 4, 新增, NULL, sys:role:add, 2, NULL, 0);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (19, 4, 修改, NULL, sys:role:edit, 2, NULL, 0);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (20, 4, 删除, NULL, sys:role:delete, 2, NULL, 0);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (21, 5, 查看, NULL, sys:menu:view, 2, NULL, 0);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (22, 5, 新增, NULL, sys:menu:add, 2, NULL, 0);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (23, 5, 修改, NULL, sys:menu:edit, 2, NULL, 0);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (24, 5, 删除, NULL, sys:menu:delete, 2, NULL, 0);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (25, 0, 内容管理, NULL, NULL, 0, el-icon-document, 0);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (26, 25, 栏目管理, /content/category, NULL, 1, el-icon-tickets, 1);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (27, 25, 文章管理, /content/artical, NULL, 1, el-icon-tickets, 2);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (28, 0, 使用案例, NULL, NULL, 0, el-icon-picture-outline, 0);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (29, 28, 国际化, /demo/i18n, NULL, 1, el-icon-edit, 1);
INSERT INTO `sys_menu` (`id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES (30, 28, 换皮肤, /demo/theme, NULL, 1, el-icon-picture, 2);
-- --------------------------------------
--  Records of `sys_role_menu`
-- --------------------------------------
INSERT INTO `sys_role_menu` (`id`, `role_id`, `menu_id`) VALUES (1, 2, 25);
INSERT INTO `sys_role_menu` (`id`, `role_id`, `menu_id`) VALUES (2, 2, 26);
INSERT INTO `sys_role_menu` (`id`, `role_id`, `menu_id`) VALUES (3, 2, 27);
INSERT INTO `sys_role_menu` (`id`, `role_id`, `menu_id`) VALUES (4, 2, 28);
INSERT INTO `sys_role_menu` (`id`, `role_id`, `menu_id`) VALUES (5, 2, 29);
INSERT INTO `sys_role_menu` (`id`, `role_id`, `menu_id`) VALUES (6, 2, 30);
INSERT INTO `sys_role_menu` (`id`, `role_id`, `menu_id`) VALUES (7, 3, 25);
INSERT INTO `sys_role_menu` (`id`, `role_id`, `menu_id`) VALUES (8, 3, 26);
INSERT INTO `sys_role_menu` (`id`, `role_id`, `menu_id`) VALUES (9, 3, 27);
INSERT INTO `sys_role_menu` (`id`, `role_id`, `menu_id`) VALUES (10, 3, 28);
INSERT INTO `sys_role_menu` (`id`, `role_id`, `menu_id`) VALUES (11, 3, 29);
INSERT INTO `sys_role_menu` (`id`, `role_id`, `menu_id`) VALUES (12, 3, 30);

-- --------------------------------------
--  Records of `sys_dict`
-- --------------------------------------
INSERT INTO `sys_dict` (`id`, `value`, `label`, `type`, `description`, `sort`) VALUES (1, male, , sex, 男性, 0);
INSERT INTO `sys_dict` (`id`, `value`, `label`, `type`, `description`, `sort`) VALUES (2, female, , sex, 女性, 1);

 

然后使用Mybatis-Generator自动生成Model,还有Mapper类,以及*.xml文件

一、首先在pom.xml中引入pagehelper-spring-boot-starter

     <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>${pagehelper.version}</version>
        </dependency>

完整的pom如下:

<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.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.louis.springboot.demo</groupId>
    <artifactId>springboot-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <mybatis.spring.version>1.3.2</mybatis.spring.version>
        <com.alibaba.druid.version>1.1.10</com.alibaba.druid.version>
        <log4j.version>1.2.17</log4j.version>
        <pagehelper.version>1.2.5</pagehelper.version>
    </properties>

    <dependencies>
        <!-- spring boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        
        <!-- mybatis -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>${mybatis.spring.version}</version>
        </dependency>
        <!-- mysql -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
           <groupId>com.alibaba</groupId>
           <artifactId>druid-spring-boot-starter</artifactId>
           <version>${com.alibaba.druid.version}</version>
        </dependency>
        <!-- log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <!-- swagger -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
        <!-- pagehelper -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>${pagehelper.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <!-- 打包时拷贝MyBatis的映射文件 -->
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/sqlmap/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>  
                <directory>src/main/resources</directory>  
                    <includes> 
                        <include>**/*.*</include>  
                    </includes> 
                    <filtering>true</filtering>  
            </resource> 
        </resources>
    </build>
</project>

 

二、然后开始编写请求的PageRequest.javaPageResult.java

PageRequest.java

public class PageRequest {

    /**
     * 当前页码
     */
    private int pageNum;
    /**
     * 每页数量
     */
    private int pageSize;
    
    public int getPageNum() {
        return pageNum;
    }
    public int getPageSize() {
        return pageSize;
    }
    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
    
    
}

PageResult.java

public class PageResult {

    //当前页码
    private int pageNum;
    //每页数量
    private int pageSize;
    //数据总条数
    private long totalSize;
    //页码总数
    private int totalPages;
    //数据
    private List<?> conent;
    public int getPageNum() {
        return pageNum;
    }
    public int getPageSize() {
        return pageSize;
    }
    public long getTotalSize() {
        return totalSize;
    }
    public int getTotalPages() {
        return totalPages;
    }
    public List<?> getConent() {
        return conent;
    }
    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
    public void setTotalSize(long totalSize) {
        this.totalSize = totalSize;
    }
    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }
    public void setConent(List<?> conent) {
        this.conent = conent;
    }
    
    
}

 

三、然后开始编写Controller类

@RestController
@RequestMapping("menu")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;
    
    /**
     * @Title: findPage 
     * @Description: 此处controller要使用POST的请求方式,主要是@RequestBody 提交的数据需要时POST形式提交
     * @param pageRequest 
     * @return HttpResult    返回类型 
     * @throws
     */
    @PostMapping(value = "/findPage")
    public HttpResult findPage(@RequestBody PageRequest pageRequest ) {
        return HttpResult.ok(this.sysMenuService.findPage(pageRequest ));
    }
}

SysMenuService.java

public interface SysMenuService extends CurdService<SysMenu>{

    /** 
     * @Title: findPage 
     * @Description: 分页查询接口 
     * @param @param pageQuery
     * @param @return  参数说明 
     * @return Object    返回类型 
     * @throws 
     */
    PageResult findPage(PageRequest pageRequest);

}

SysMenuServiceImpl.java

@Service
public class SysMenuServiceImpl implements SysMenuService {

    @Autowired
    private SysMenuMapper sysMenuMapper;

    /*
     * Title: save
     *Description: 
     * @param record
     * @return 
     * @see com.louis.kitty.core.service.CurdService#save(java.lang.Object) 
     */
    @Override
    public int save(SysMenu record) {
        return this.sysMenuMapper.insertSelective(record);
    }

    /*
     * Title: upate
     *Description: 
     * @param record
     * @return 
     * @see com.louis.kitty.core.service.CurdService#upate(java.lang.Object) 
     */
    @Override
    public int upate(SysMenu record) {
        return this.sysMenuMapper.updateByPrimaryKeySelective(record);
    }

    /*
     * Title: delete
     *Description: 
     * @param record
     * @return 
     * @see com.louis.kitty.core.service.CurdService#delete(java.lang.Object) 
     */
    @Override
    public int delete(SysMenu record) {
        return this.sysMenuMapper.deleteByPrimaryKey(record.getId());
    }

    /*
     * Title: delete
     *Description: 
     * @param records
     * @return 
     * @see com.louis.kitty.core.service.CurdService#delete(java.util.List) 
     */
    @Override
    public int delete(List<SysMenu> records) {
        for (SysMenu record : records) {
            delete(record);
        }
        return 1;
    }

    /*
     * Title: findById
     *Description: 
     * @param id
     * @return 
     * @see com.louis.kitty.core.service.CurdService#findById(java.lang.Long) 
     */
    @Override
    public SysMenu findById(Long id) {
        return this.sysMenuMapper.selectByPrimaryKey(id);
    }

    /*
     * Title: findPage
     *Description: 
     * @param pageResult
     * @return 
     * @see com.louis.kitty.core.service.CurdService#findPage(com.louis.kitty.admin.page.PageRequest) 
     */
    @Override
    public PageResult findPage(PageRequest pageRequest) {
        return PageUtils.getPageResult(pageRequest, pageInfo(pageRequest));
    }

    /** 
     * @Title: pageInfo 
     * @Description: TODO(这里用一句话描述这个方法的作用) 
     * @param @param pageRequest
     * @param @return  参数说明 
     * @return PageInfo<?>    返回类型 
     * @throws 
     */
    private PageInfo<SysMenu> pageInfo(PageRequest pageRequest) {
        int pageNum = pageRequest.getPageNum();
        int pageSize = pageRequest.getPageSize();
        PageHelper.startPage(pageNum, pageSize);
        List<SysMenu> sysMenus = this.sysMenuMapper.findPage();
        return new PageInfo<SysMenu>(sysMenus);
    }
}

其中基础服务类如下CurdService.java

/** 
 * @ClassName: CurdService 
 * @Description: 通用CURD操作
 * @author lr
 * @date 2018年11月6日 上午10:42:23 
 *  
 */
public interface CurdService<T> {
    /**
     * @Title: save 
     * @Description: 保存操作
     * @param @param record
     * @param @return  参数说明 
     * @return int    返回类型 
     * @throws
     */
    int save(T record);
    /**
     * @Title: upate 
     * @Description: 更新操作
     * @param @param record
     * @param @return  参数说明 
     * @return int    返回类型 
     * @throws
     */
    int upate(T record);
    /**
     * @Title: delete 
     * @Description: 删除操作
     * @param @param record
     * @param @return  参数说明 
     * @return int    返回类型 
     * @throws
     */
    int delete(T record);
    /**
     * @Title: delete 
     * @Description: 批量删除操作
     * @param @param records
     * @param @return  参数说明 
     * @return int    返回类型 
     * @throws
     */
    int delete(List<T> records);
    /**
     * @Title: findById 
     * @Description: 根据ID查询
     * @param @param id
     * @param @return  参数说明 
     * @return T    返回类型 
     * @throws
     */
    T findById(Long id);
    
    /**
     * @Title: findPage 
     * @Description: 分页查询
     * @param pageRequest 自定义统一分页查询要求
     * @return PageResult 自定义统一分返回类型 
     * @throws
     */
    PageResult findPage(PageRequest pageRequest);
}

controller的返回结果HttpResult.java

/** 
 * @ClassName: HttpResult 
 * @Description: TODO(这里用一句话描述这个类的作用) 
 * @author lr
 * @date 2018年11月6日 上午10:32:30 
 *  
 */
public class HttpResult {

    private int code;
    private String msg;
    private Object data;
    
    public static HttpResult error() {
        return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常,请联系管理员");
    }
    
    public static HttpResult error(String msg) {
        return  error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
    }
    
    public static HttpResult error(int code, String msg) {
        HttpResult r = new HttpResult();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }
    
    public static HttpResult ok() {
        return new HttpResult();
    }
    
    public static HttpResult ok(Object data) {
        HttpResult r = new HttpResult();
        r.setData(data);
        return r;
    }
    
    public static HttpResult ok(String msg) {
        HttpResult r = new HttpResult();
        r.setMsg(msg);
        return r;
    }
    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public Object getData() {
        return data;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setData(Object data) {
        this.data = data;
    }
    
    
}

ReflectionUtils.java 类如下:

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 反射相关辅助方法
 * @author Louis
 * @date Aug 19, 2018
 */
public class ReflectionUtils {

    
    /**
     * 根据方法名调用指定对象的方法
     * @param object 要调用方法的对象
     * @param method 要调用的方法名
     * @param args 参数对象数组
     * @return
     */
    public static Object invoke(Object object, String method, Object... args) {
        Object result = null;
        Class<? extends Object> clazz = object.getClass();
        Method queryMethod = getMethod(clazz, method, args);
        if(queryMethod != null) {
            try {
                result = queryMethod.invoke(object, args);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        } else {
            try {
                throw new NoSuchMethodException(clazz.getName() + " 类中没有找到 " + method + " 方法。");
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            }
        }
        return result;
    }
    
    /**
     * 根据方法名和参数对象查找方法
     * @param clazz
     * @param name
     * @param args 参数实例数据
     * @return
     */
    public static Method getMethod(Class<? extends Object> clazz, String name, Object[] args) {
        Method queryMethod = null;
        Method[] methods = clazz.getMethods();
        for(Method method:methods) {
            if(method.getName().equals(name)) {
                Class<?>[] parameterTypes = method.getParameterTypes();
                if(parameterTypes.length == args.length) {
                    boolean isSameMethod = true;
                    for(int i=0; i<parameterTypes.length; i++) {
                        Object arg = args[i];
                        if(arg == null) {
                            arg = "";
                        }
                        if(!parameterTypes[i].equals(args[i].getClass())) {
                            isSameMethod = false;
                        }
                    }
                    if(isSameMethod) {
                        queryMethod = method;
                        break ;
                    }
                }
            }
        }
        return queryMethod;
    }
}

 

然后启动就可以看到接口数据了:

技术分享图片

技术分享图片

 

主要返回的数据如下:

{
  "code": 0,
  "msg": null,
  "data": {
    "pageNum": 1,
    "pageSize": 10,
    "totalSize": 29,
    "totalPages": 3,
    "conent": [
      {
        "id": 1,
        "createBy": null,
        "createTime": null,
        "lastUpdateBy": null,
        "lastUpdateTime": null,
        "parentId": 0,
        "name": "系统管理",
        "url": null,
        "perms": null,
        "type": 0,
        "icon": "fa el-icon-setting",
        "orderNum": 0,
        "delFlag": 0,
        "parentName": null,
        "level": null,
        "children": null
      },
      {
        "id": 2,
        "createBy": null,
        "createTime": null,
        "lastUpdateBy": null,
        "lastUpdateTime": null,
        "parentId": 1,
        "name": "用户管理",
        "url": "/sys/user",
        "perms": null,
        "type": 1,
        "icon": "el-icon-service",
        "orderNum": 1,
        "delFlag": 0,
        "parentName": null,
        "level": null,
        "children": null
      },
      {
        "id": 3,
        "createBy": null,
        "createTime": null,
        "lastUpdateBy": null,
        "lastUpdateTime": null,
        "parentId": 1,
        "name": "机构管理",
        "url": "/sys/dept",
        "perms": null,
        "type": 1,
        "icon": "el-icon-news",
        "orderNum": 2,
        "delFlag": 0,
        "parentName": null,
        "level": null,
        "children": null
      },
      {
        "id": 4,
        "createBy": null,
        "createTime": null,
        "lastUpdateBy": null,
        "lastUpdateTime": null,
        "parentId": 1,
        "name": "角色管理",
        "url": "/sys/role",
        "perms": null,
        "type": 1,
        "icon": "el-icon-view",
        "orderNum": 4,
        "delFlag": 0,
        "parentName": null,
        "level": null,
        "children": null
      },
      {
        "id": 5,
        "createBy": null,
        "createTime": null,
        "lastUpdateBy": null,
        "lastUpdateTime": null,
        "parentId": 1,
        "name": "菜单管理",
        "url": "/sys/menu",
        "perms": null,
        "type": 1,
        "icon": "el-icon-menu",
        "orderNum": 5,
        "delFlag": 0,
        "parentName": null,
        "level": null,
        "children": null
      },
      {
        "id": 6,
        "createBy": null,
        "createTime": null,
        "lastUpdateBy": null,
        "lastUpdateTime": null,
        "parentId": 1,
        "name": "SQL监控",
        "url": "/druid/sql",
        "perms": null,
        "type": 1,
        "icon": "el-icon-info",
        "orderNum": 6,
        "delFlag": 0,
        "parentName": null,
        "level": null,
        "children": null
      },
      {
        "id": 8,
        "createBy": null,
        "createTime": null,
        "lastUpdateBy": null,
        "lastUpdateTime": null,
        "parentId": 1,
        "name": "系统日志",
        "url": "/sys/log",
        "perms": "sys:log:view",
        "type": 1,
        "icon": "el-icon-info",
        "orderNum": 7,
        "delFlag": 0,
        "parentName": null,
        "level": null,
        "children": null
      },
      {
        "id": 9,
        "createBy": null,
        "createTime": null,
        "lastUpdateBy": null,
        "lastUpdateTime": null,
        "parentId": 2,
        "name": "查看",
        "url": null,
        "perms": "sys:user:view",
        "type": 2,
        "icon": null,
        "orderNum": 0,
        "delFlag": 0,
        "parentName": null,
        "level": null,
        "children": null
      },
      {
        "id": 10,
        "createBy": null,
        "createTime": null,
        "lastUpdateBy": null,
        "lastUpdateTime": null,
        "parentId": 2,
        "name": "新增",
        "url": null,
        "perms": "sys:user:add",
        "type": 2,
        "icon": null,
        "orderNum": 0,
        "delFlag": 0,
        "parentName": null,
        "level": null,
        "children": null
      },
      {
        "id": 11,
        "createBy": null,
        "createTime": null,
        "lastUpdateBy": null,
        "lastUpdateTime": null,
        "parentId": 2,
        "name": "修改",
        "url": null,
        "perms": "sys:user:edit",
        "type": 2,
        "icon": null,
        "orderNum": 0,
        "delFlag": 0,
        "parentName": null,
        "level": null,
        "children": null
      }
    ]
  }
}

 

SpringBoot 分页处理

标签:serve   col   flag   打包   技术   nal   val   edit   git   

原文地址:https://www.cnblogs.com/lr393993507/p/9914408.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!