一:为什么要自己写?
- 目前的SpringSucrity 、Apache Shiro 也会有无法满足实际的业务的情况下的相关配置内容。
- 目前的SpringSucrity 、Apache Shiro 没有界面操作和查看
- 目前的SpringSucrity 、Apache Shiro 无法达到期望更细致的管理
二:基本目标
- 基于开展的RBAC实现
- 易于扩展,能灵活适应需求的变化
- 所有管理都有界面方便操作
三:需要开发的功能确定
3.1、配置管理类功能
配置管理类功能-3.1.1:部门列表
配置管理类功能-3.1.1.1:新增部门
配置管理类功能-3.1.2:用户列表
配置管理类功能-3.1.2.1:新增用户
配置管理类功能-3.1.3:权限模块列表
配置管理类功能-3.1.3.1:新增权限模块
配置管理类功能-3.1.4:权限点列表
配置管理类功能-3.1.4.1:新增权限点
配置管理类功能-3.1.5:角色列表
配置管理类功能-3.1.5.1:新增角色
配置管理类功能-3.1.5.2:角色与权限
配置管理类功能-3.1.5.3:角色与用户
3.2:配置管理类功能
配置管理类功能-3.2.1:用户、权限、角色的管理界面(扩展用:部门、权限模块)
配置管理类功能-3.2.2:角色-用户管理、角色-权限管理
配置管理类功能-3.2.3:权限更新日志管理
3.3:权限拦截类功能
权限拦截类功能-3.3.1:在切面(filter) 做权限拦截
权限拦截类功能-3.3.2:确定用户是否拥有某个权限
3.4:辅助类功能
辅助类功能-3.4.1:缓存(redis)封装和使用
辅助类功能-3.4.2:各种树形结构生成
- 部门树
- 权限模块树
- 角色权限树
- 用户权限树
辅助类功能-3.4.3:权限操作恢复
四:详细表设计
4.1:用户表、部门表
4.2:权限表、权限模块表
4.3:角色相关表
4.4:权限相关日志表
4.5:详细表结构设计相关注意点
- 每个表都有自己的主键
- 字段尽量定义为Not null
- 尽量为每个字段添加备注
- 数据库字段统一小写,单词之间使用下划线分隔
- 使用InnoDB储存引擎
- 可以使用Varchar的字段尽可能不使用 text、blob类型
- 表字符集可以选择utf-8
4.6:创建表脚本
-- ----------------------------
-- Table structure for `sys_acl`
-- ----------------------------
DROP TABLE IF EXISTS `sys_acl`;
CREATE TABLE `sys_acl` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '权限id',
`code` varchar(20) NOT NULL DEFAULT '' COMMENT '权限码',
`name` varchar(20) NOT NULL DEFAULT '' COMMENT '权限名称',
`acl_module_id` int(11) NOT NULL DEFAULT '0' COMMENT '权限所在的权限模块id',
`url` varchar(100) NOT NULL DEFAULT '' COMMENT '请求的url, 可以填正则表达式',
`type` int(11) NOT NULL DEFAULT '3' COMMENT '类型,1:菜单,2:按钮,3:其他',
`status` int(11) NOT NULL DEFAULT '1' COMMENT '状态,1:正常,0:冻结',
`seq` int(11) NOT NULL DEFAULT '0' COMMENT '权限在当前模块下的顺序,由小到大',
`remark` varchar(200) DEFAULT '' COMMENT '备注',
`operator` varchar(20) NOT NULL DEFAULT '' COMMENT '操作者',
`operate_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次更新时间',
`operate_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后一个更新者的ip地址',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Records of `sys_acl`
-- ----------------------------
BEGIN;
INSERT INTO `sys_acl` VALUES ('1', '20171015095130_26', '进入产品管理界面', '1', '/sys/product/product.page', '1', '1', '1', '', 'Admin', '2017-10-15 09:51:30', '0:0:0:0:0:0:0:1'), ('2', '20171015095322_14', '查询产品列表', '1', '/sys/product/page.json', '2', '1', '2', '', 'Admin', '2017-10-15 09:53:22', '0:0:0:0:0:0:0:1'), ('3', '20171015095350_69', '产品上架', '1', '/sys/product/online.json', '2', '1', '3', '', 'Admin', '2017-10-15 09:53:51', '0:0:0:0:0:0:0:1'), ('4', '20171015095420_7', '产品下架', '1', '/sys/product/offline.json', '2', '1', '4', '', 'Admin', '2017-10-15 10:11:28', '0:0:0:0:0:0:0:1'), ('5', '20171015212626_63', '进入订单页', '2', '/sys/order/order.page', '1', '1', '1', '', 'Admin', '2017-10-15 21:26:27', '0:0:0:0:0:0:0:1'), ('6', '20171015212657_12', '查询订单列表', '2', '/sys/order/list.json', '2', '1', '2', '', 'Admin', '2017-10-15 21:26:57', '0:0:0:0:0:0:0:1'), ('7', '20171015212907_36', '进入权限管理页', '7', '/sys/aclModule/acl.page', '1', '1', '1', '', 'Admin', '2017-10-15 21:29:07', '0:0:0:0:0:0:0:1'), ('8', '20171015212938_27', '进入角色管理页', '8', '/sys/role/role.page', '1', '1', '1', '', 'Admin', '2017-10-16 17:49:38', '0:0:0:0:0:0:0:1'), ('9', '20171015213009_0', '进入用户管理页', '9', '/sys/dept/dept.page', '1', '1', '1', '', 'Admin', '2017-10-15 21:30:09', '0:0:0:0:0:0:0:1'), ('10', '20171016230429_8', '进入权限更新记录页面', '11', '/sys/log/log.page', '1', '1', '1', '', 'Admin', '2017-10-16 23:04:49', '0:0:0:0:0:0:0:1');
COMMIT;
-- ----------------------------
-- Table structure for `sys_acl_module`
-- ----------------------------
DROP TABLE IF EXISTS `sys_acl_module`;
CREATE TABLE `sys_acl_module` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '权限模块id',
`name` varchar(20) NOT NULL DEFAULT '' COMMENT '权限模块名称',
`parent_id` int(11) NOT NULL DEFAULT '0' COMMENT '上级权限模块id',
`level` varchar(200) NOT NULL DEFAULT '' COMMENT '权限模块层级',
`seq` int(11) NOT NULL DEFAULT '0' COMMENT '权限模块在当前层级下的顺序,由小到大',
`status` int(11) NOT NULL DEFAULT '1' COMMENT '状态,1:正常,0:冻结',
`remark` varchar(200) DEFAULT '' COMMENT '备注',
`operator` varchar(20) NOT NULL DEFAULT '' COMMENT '操作者',
`operate_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次操作时间',
`operate_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后一次更新操作者的ip地址',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
-- ----------------------------
-- Records of `sys_acl_module`
-- ----------------------------
BEGIN;
INSERT INTO `sys_acl_module` VALUES ('1', '产品管理', '0', '0', '1', '1', 'product', 'Admin', '2017-10-14 21:13:15', '0:0:0:0:0:0:0:1'), ('2', '订单管理', '0', '0', '2', '1', '', 'Admin', '2017-10-14 20:17:11', '0:0:0:0:0:0:0:1'), ('3', '公告管理', '0', '0', '3', '1', '', 'Admin', '2017-10-14 20:17:21', '0:0:0:0:0:0:0:1'), ('4', '出售中产品管理', '1', '0.1', '1', '1', '', 'Admin', '2017-10-14 21:13:39', '0:0:0:0:0:0:0:1'), ('5', '下架产品管理', '1', '0.1', '2', '1', '', 'Admin', '2017-10-14 20:18:02', '0:0:0:0:0:0:0:1'), ('6', '权限管理', '0', '0', '4', '1', '', 'Admin', '2017-10-15 21:27:37', '0:0:0:0:0:0:0:1'), ('7', '权限管理', '6', '0.6', '1', '1', '', 'Admin', '2017-10-15 21:27:57', '0:0:0:0:0:0:0:1'), ('8', '角色管理', '6', '0.6', '2', '1', '', 'Admin', '2017-10-15 21:28:22', '0:0:0:0:0:0:0:1'), ('9', '用户管理', '6', '0.6', '2', '1', '', 'Admin', '2017-10-15 21:28:36', '0:0:0:0:0:0:0:1'), ('10', '运维管理', '0', '0', '6', '1', '', 'Admin', '2017-10-16 23:03:37', '0:0:0:0:0:0:0:1'), ('11', '权限更新记录管理', '6', '0.6', '4', '1', '', 'Admin', '2017-10-16 23:04:07', '0:0:0:0:0:0:0:1');
COMMIT;
-- ----------------------------
-- Table structure for `sys_dept`
-- ----------------------------
DROP TABLE IF EXISTS `sys_dept`;
CREATE TABLE `sys_dept` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '部门id',
`name` varchar(20) NOT NULL DEFAULT '' COMMENT '部门名称',
`parent_id` int(11) NOT NULL DEFAULT '0' COMMENT '上级部门id',
`level` varchar(200) NOT NULL DEFAULT '' COMMENT '部门层级',
`seq` int(11) NOT NULL DEFAULT '0' COMMENT '部门在当前层级下的顺序,由小到大',
`remark` varchar(200) DEFAULT '' COMMENT '备注',
`operator` varchar(20) NOT NULL DEFAULT '' COMMENT '操作者',
`operate_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次操作时间',
`operate_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后一次更新操作者的ip地址',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Records of `sys_dept`
-- ----------------------------
BEGIN;
INSERT INTO `sys_dept` VALUES ('1', '技术部', '0', '0', '1', '技术部', 'system', '2017-10-11 07:21:40', '127.0.0.1'), ('2', '后端开发', '1', '0.1', '1', '后端', 'system-update', '2017-10-12 07:56:16', '127.0.0.1'), ('3', '前端开发', '1', '0.1', '2', '', 'system-update', '2017-10-14 11:29:45', '127.0.0.1'), ('4', 'UI设计', '1', '0.1', '3', '', 'system', '2017-10-12 07:55:43', '127.0.0.1'), ('11', '产品部', '0', '0', '2', '', 'Admin', '2017-10-16 22:52:29', '0:0:0:0:0:0:0:1'), ('12', '客服部', '0', '0', '4', '', 'Admin', '2017-10-17 00:22:55', '0:0:0:0:0:0:0:1');
COMMIT;
-- ----------------------------
-- Table structure for `sys_log`
-- ----------------------------
DROP TABLE IF EXISTS `sys_log`;
CREATE TABLE `sys_log` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`type` int(11) NOT NULL DEFAULT '0' COMMENT '权限更新的类型,1:部门,2:用户,3:权限模块,4:权限,5:角色,6:角色用户关系,7:角色权限关系',
`target_id` int(11) NOT NULL COMMENT '基于type后指定的对象id,比如用户、权限、角色等表的主键',
`old_value` text COMMENT '旧值',
`new_value` text COMMENT '新值',
`operator` varchar(20) NOT NULL DEFAULT '' COMMENT '操作者',
`operate_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次更新的时间',
`operate_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后一次更新者的ip地址',
`status` int(11) NOT NULL DEFAULT '0' COMMENT '当前是否复原过,0:没有,1:复原过',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Records of `sys_log`
-- ----------------------------
BEGIN;
INSERT INTO `sys_log` VALUES ('2', '1', '12', '', '{\"id\":12,\"name\":\"客服部\",\"parentId\":0,\"level\":\"0\",\"seq\":3,\"operator\":\"Admin\",\"operateTime\":1508166002610,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', 'Admin', '2017-10-16 23:00:03', '0:0:0:0:0:0:0:1', '1'), ('3', '1', '12', '{\"id\":12,\"name\":\"客服部\",\"parentId\":0,\"level\":\"0\",\"seq\":3,\"operator\":\"Admin\",\"operateTime\":1508166003000,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', '{\"id\":12,\"name\":\"客服部\",\"parentId\":0,\"level\":\"0\",\"seq\":4,\"operator\":\"Admin\",\"operateTime\":1508166009313,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', 'Admin', '2017-10-16 23:00:09', '0:0:0:0:0:0:0:1', '1'), ('4', '2', '4', '', '{\"id\":4,\"username\":\"Kate\",\"telephone\":\"13144445555\",\"mail\":\"kate@qq.com\",\"password\":\"25D55AD283AA400AF464C76D713C07AD\",\"deptId\":1,\"status\":1,\"operator\":\"Admin\",\"operateTime\":1508166166297,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', 'Admin', '2017-10-16 23:02:46', '0:0:0:0:0:0:0:1', '1'), ('5', '2', '4', '{\"id\":4,\"username\":\"Kate\",\"telephone\":\"13144445555\",\"mail\":\"kate@qq.com\",\"password\":\"25D55AD283AA400AF464C76D713C07AD\",\"deptId\":1,\"status\":1,\"operator\":\"Admin\",\"operateTime\":1508166166000,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', '{\"id\":4,\"username\":\"Kate\",\"telephone\":\"13144445555\",\"mail\":\"kate@qq.com\",\"deptId\":1,\"status\":1,\"remark\":\"sss\",\"operator\":\"Admin\",\"operateTime\":1508166171320,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', 'Admin', '2017-10-16 23:02:51', '0:0:0:0:0:0:0:1', '1'), ('6', '3', '10', '', '{\"id\":10,\"name\":\"运维管理\",\"parentId\":0,\"level\":\"0\",\"seq\":5,\"status\":1,\"operator\":\"Admin\",\"operateTime\":1508166212527,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', 'Admin', '2017-10-16 23:03:33', '0:0:0:0:0:0:0:1', '1'), ('7', '3', '10', '{\"id\":10,\"name\":\"运维管理\",\"parentId\":0,\"level\":\"0\",\"seq\":5,\"status\":1,\"operator\":\"Admin\",\"operateTime\":1508166213000,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', '{\"id\":10,\"name\":\"运维管理\",\"parentId\":0,\"level\":\"0\",\"seq\":6,\"status\":1,\"operator\":\"Admin\",\"operateTime\":1508166217376,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', 'Admin', '2017-10-16 23:03:37', '0:0:0:0:0:0:0:1', '1'), ('8', '3', '11', '', '{\"id\":11,\"name\":\"权限更新记录管理\",\"parentId\":6,\"level\":\"0.6\",\"seq\":4,\"status\":1,\"operator\":\"Admin\",\"operateTime\":1508166246805,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', 'Admin', '2017-10-16 23:04:07', '0:0:0:0:0:0:0:1', '1'), ('9', '4', '10', '', '{\"id\":10,\"code\":\"20171016230429_8\",\"name\":\"进入权限更新记录页面\",\"aclModuleId\":1,\"url\":\"/sys/log/log.page\",\"type\":1,\"status\":1,\"seq\":1,\"operator\":\"Admin\",\"operateTime\":1508166269419,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', 'Admin', '2017-10-16 23:04:29', '0:0:0:0:0:0:0:1', '1'), ('10', '4', '10', '{\"id\":10,\"code\":\"20171016230429_8\",\"name\":\"进入权限更新记录页面\",\"aclModuleId\":1,\"url\":\"/sys/log/log.page\",\"type\":1,\"status\":1,\"seq\":1,\"operator\":\"Admin\",\"operateTime\":1508166269000,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', '{\"id\":10,\"name\":\"进入权限更新记录页面\",\"aclModuleId\":11,\"url\":\"/sys/log/log.page\",\"type\":1,\"status\":1,\"seq\":1,\"operator\":\"Admin\",\"operateTime\":1508166288589,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', 'Admin', '2017-10-16 23:04:49', '0:0:0:0:0:0:0:1', '1'), ('11', '5', '5', '', '{\"id\":5,\"name\":\"运维管理员\",\"type\":1,\"status\":1,\"operator\":\"Admin\",\"operateTime\":1508166301130,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', 'Admin', '2017-10-16 23:05:01', '0:0:0:0:0:0:0:1', '1'), ('12', '5', '5', '{\"id\":5,\"name\":\"运维管理员\",\"type\":1,\"status\":1,\"operator\":\"Admin\",\"operateTime\":1508166301000,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', '{\"id\":5,\"name\":\"运维管理员\",\"type\":1,\"status\":1,\"remark\":\"运维\",\"operator\":\"Admin\",\"operateTime\":1508166307317,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', 'Admin', '2017-10-16 23:05:07', '0:0:0:0:0:0:0:1', '1'), ('13', '6', '4', '[7,8,9]', '[7,8,9,10]', 'Admin', '2017-10-16 23:34:39', '0:0:0:0:0:0:0:1', '1'), ('14', '7', '4', '[1]', '[1,4]', 'Admin', '2017-10-16 23:34:44', '0:0:0:0:0:0:0:1', '1'), ('15', '2', '5', '', '{\"id\":5,\"username\":\"服务员A\",\"telephone\":\"18677778888\",\"mail\":\"service@qq.com\",\"password\":\"25D55AD283AA400AF464C76D713C07AD\",\"deptId\":12,\"status\":1,\"operator\":\"Admin\",\"operateTime\":1508170918338,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', 'Admin', '2017-10-17 00:21:58', '0:0:0:0:0:0:0:1', '1'), ('16', '2', '5', '{\"id\":5,\"username\":\"服务员A\",\"telephone\":\"18677778888\",\"mail\":\"service@qq.com\",\"password\":\"25D55AD283AA400AF464C76D713C07AD\",\"deptId\":12,\"status\":1,\"operator\":\"Admin\",\"operateTime\":1508170918000,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', '{\"id\":5,\"username\":\"服务员B\",\"telephone\":\"18677778888\",\"mail\":\"service@qq.com\",\"deptId\":12,\"status\":1,\"operator\":\"Admin\",\"operateTime\":1508170924698,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', 'Admin', '2017-10-17 00:22:05', '0:0:0:0:0:0:0:1', '1'), ('17', '2', '5', '{\"id\":5,\"username\":\"服务员B\",\"telephone\":\"18677778888\",\"mail\":\"service@qq.com\",\"password\":\"25D55AD283AA400AF464C76D713C07AD\",\"deptId\":12,\"status\":1,\"operator\":\"Admin\",\"operateTime\":1508170925000,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', '{\"id\":5,\"username\":\"服务员A\",\"telephone\":\"18677778888\",\"mail\":\"service@qq.com\",\"password\":\"25D55AD283AA400AF464C76D713C07AD\",\"deptId\":12,\"status\":1,\"operator\":\"Admin\",\"operateTime\":1508170934791,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', 'Admin', '2017-10-17 00:22:15', '0:0:0:0:0:0:0:1', '1'), ('18', '1', '12', '{\"id\":12,\"name\":\"客服部\",\"parentId\":0,\"level\":\"0\",\"seq\":4,\"operator\":\"Admin\",\"operateTime\":1508166009000,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', '{\"id\":12,\"name\":\"客服部A\",\"parentId\":0,\"level\":\"0\",\"seq\":4,\"operator\":\"Admin\",\"operateTime\":1508170966051,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', 'Admin', '2017-10-17 00:22:46', '0:0:0:0:0:0:0:1', '1'), ('19', '1', '12', '{\"id\":12,\"name\":\"客服部A\",\"parentId\":0,\"level\":\"0\",\"seq\":4,\"operator\":\"Admin\",\"operateTime\":1508170966000,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', '{\"id\":12,\"name\":\"客服部\",\"parentId\":0,\"level\":\"0\",\"seq\":4,\"operator\":\"Admin\",\"operateTime\":1508170975242,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', 'Admin', '2017-10-17 00:22:55', '0:0:0:0:0:0:0:1', '1'), ('20', '5', '5', '{\"id\":5,\"name\":\"运维管理员\",\"type\":1,\"status\":1,\"remark\":\"运维\",\"operator\":\"Admin\",\"operateTime\":1508166307000,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', '{\"id\":5,\"name\":\"运维管理员A\",\"type\":1,\"status\":1,\"remark\":\"运维\",\"operator\":\"Admin\",\"operateTime\":1508170997531,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', 'Admin', '2017-10-17 00:23:18', '0:0:0:0:0:0:0:1', '1'), ('21', '5', '5', '{\"id\":5,\"name\":\"运维管理员A\",\"type\":1,\"status\":1,\"remark\":\"运维\",\"operator\":\"Admin\",\"operateTime\":1508170998000,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', '{\"id\":5,\"name\":\"运维管理员\",\"type\":1,\"status\":1,\"remark\":\"运维\",\"operator\":\"Admin\",\"operateTime\":1508171007651,\"operateIp\":\"0:0:0:0:0:0:0:1\"}', 'Admin', '2017-10-17 00:23:28', '0:0:0:0:0:0:0:1', '1'), ('22', '7', '4', '[1,4]', '[1,4,2,3,5]', 'Admin', '2017-10-17 00:23:53', '0:0:0:0:0:0:0:1', '1'), ('23', '7', '4', '[1,4,2,3,5]', '[1,4]', 'Admin', '2017-10-17 00:24:04', '0:0:0:0:0:0:0:1', '1'), ('24', '6', '5', '[]', '[7,8,9,10]', 'Admin', '2017-10-17 00:24:23', '0:0:0:0:0:0:0:1', '1'), ('25', '6', '5', '[7,8,9,10]', '[]', 'Admin', '2017-10-17 00:24:34', '0:0:0:0:0:0:0:1', '1');
COMMIT;
-- ----------------------------
-- Table structure for `sys_role`
-- ----------------------------
DROP TABLE IF EXISTS `sys_role`;
CREATE TABLE `sys_role` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '角色id',
`name` varchar(20) NOT NULL,
`type` int(11) NOT NULL DEFAULT '1' COMMENT '角色的类型,1:管理员角色,2:其他',
`status` int(11) NOT NULL DEFAULT '1' COMMENT '状态,1:可用,0:冻结',
`remark` varchar(200) DEFAULT '' COMMENT '备注',
`operator` varchar(20) NOT NULL DEFAULT '' COMMENT '操作者',
`operate_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次更新的时间',
`operate_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后一次更新者的ip地址',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Records of `sys_role`
-- ----------------------------
BEGIN;
INSERT INTO `sys_role` VALUES ('1', '产品管理员', '1', '1', '', 'Admin', '2017-10-15 12:42:47', '0:0:0:0:0:0:0:1'), ('2', '订单管理员', '1', '1', '', 'Admin', '2017-10-15 12:18:59', '0:0:0:0:0:0:0:1'), ('3', '公告管理员', '1', '1', '', 'Admin', '2017-10-15 12:19:10', '0:0:0:0:0:0:0:1'), ('4', '权限管理员', '1', '1', '', 'Admin', '2017-10-15 21:30:36', '0:0:0:0:0:0:0:1'), ('5', '运维管理员', '1', '1', '运维', 'Admin', '2017-10-17 00:23:28', '0:0:0:0:0:0:0:1');
COMMIT;
-- ----------------------------
-- Table structure for `sys_role_acl`
-- ----------------------------
DROP TABLE IF EXISTS `sys_role_acl`;
CREATE TABLE `sys_role_acl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`role_id` int(11) NOT NULL COMMENT '角色id',
`acl_id` int(11) NOT NULL COMMENT '权限id',
`operator` varchar(20) NOT NULL DEFAULT '' COMMENT '操作者',
`operate_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次更新的时间',
`operate_ip` varchar(200) NOT NULL DEFAULT '' COMMENT '最后一次更新者的ip',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Records of `sys_role_acl`
-- ----------------------------
BEGIN;
INSERT INTO `sys_role_acl` VALUES ('9', '4', '7', 'Admin', '2017-10-16 23:34:39', '0:0:0:0:0:0:0:1'), ('10', '4', '8', 'Admin', '2017-10-16 23:34:39', '0:0:0:0:0:0:0:1'), ('11', '4', '9', 'Admin', '2017-10-16 23:34:39', '0:0:0:0:0:0:0:1'), ('12', '4', '10', 'Admin', '2017-10-16 23:34:39', '0:0:0:0:0:0:0:1');
COMMIT;
-- ----------------------------
-- Table structure for `sys_role_user`
-- ----------------------------
DROP TABLE IF EXISTS `sys_role_user`;
CREATE TABLE `sys_role_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`role_id` int(11) NOT NULL COMMENT '角色id',
`user_id` int(11) NOT NULL COMMENT '用户id',
`operator` varchar(20) NOT NULL DEFAULT '' COMMENT '操作者',
`operate_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次更新的时间',
`operate_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后一次更新者的ip地址',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Records of `sys_role_user`
-- ----------------------------
BEGIN;
INSERT INTO `sys_role_user` VALUES ('16', '4', '1', 'Admin', '2017-10-17 00:24:04', '0:0:0:0:0:0:0:1'), ('17', '4', '4', 'Admin', '2017-10-17 00:24:04', '0:0:0:0:0:0:0:1');
COMMIT;
-- ----------------------------
-- Table structure for `sys_user`
-- ----------------------------
DROP TABLE IF EXISTS `sys_user`;
CREATE TABLE `sys_user` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户id',
`username` varchar(20) NOT NULL DEFAULT '' COMMENT '用户名称',
`telephone` varchar(13) NOT NULL DEFAULT '' COMMENT '手机号',
`mail` varchar(20) NOT NULL DEFAULT '' COMMENT '邮箱',
`password` varchar(40) NOT NULL DEFAULT '' COMMENT '加密后的密码',
`dept_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户所在部门的id',
`status` int(11) NOT NULL DEFAULT '1' COMMENT '状态,1:正常,0:冻结状态,2:删除',
`remark` varchar(200) DEFAULT '' COMMENT '备注',
`operator` varchar(20) NOT NULL DEFAULT '' COMMENT '操作者',
`operate_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次更新时间',
`operate_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后一次更新者的ip地址',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Records of `sys_user`
-- ----------------------------
BEGIN;
INSERT INTO `sys_user` VALUES ('1', 'Admin', '18612344321', 'admin@qq.com', '25D55AD283AA400AF464C76D713C07AD', '1', '1', 'admin', 'system', '2017-10-13 08:46:16', '127.0.0.1'), ('2', 'Jimin', '13188889999', 'jimin@qq.com', '25D55AD283AA400AF464C76D713C07AD', '1', '1', 'jimin.zheng', 'Admin', '2017-10-14 14:45:19', '127.0.0.1'), ('3', 'Jimmy', '13812344311', 'jimmy@qq.com', '25D55AD283AA400AF464C76D713C07AD', '2', '1', '', 'Admin', '2017-10-16 12:57:35', '0:0:0:0:0:0:0:1'), ('4', 'Kate', '13144445555', 'kate@qq.com', '25D55AD283AA400AF464C76D713C07AD', '1', '1', 'sss', 'Admin', '2017-10-16 23:02:51', '0:0:0:0:0:0:0:1'), ('5', '服务员A', '18677778888', 'service@qq.com', '25D55AD283AA400AF464C76D713C07AD', '12', '1', '', 'Admin', '2017-10-17 00:22:15', '0:0:0:0:0:0:0:1');
COMMIT;
五:编码实现
5.1:SpringMvc 开发环境搭建
5.2:配置环境配置
5.2.1:项目初次搭建的代码结构
5.2.2:项目启动界面
5.2.3:Pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.alan.permissionSystem</groupId>
<artifactId>PermissionSystemNew</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>PermissionSystemNew Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<springframework.version>4.3.10.RELEASE</springframework.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${springframework.version}</version>
</dependency>
<!--Spring MVC + Spring web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${springframework.version}</version>
</dependency>
<!-- mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.0</version>
</dependency>
<!-- druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.20</version>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.32</version>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.12</version>
</dependency>
<!-- Jackson -->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-guava</artifactId>
<version>2.5.3</version>
</dependency>
<!-- logback -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.8</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.22</version>
</dependency>
</dependencies>
<build>
<finalName>PermissionSystemNew</finalName>
</build>
</project>
5.2.4: index.jsp
5.2.5: web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>Archetype Created Web Application</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring beans 配置文件所在目录 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- spring mvc 配置 -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- Encoding -->
<filter>
<filter-name>encodingFilter</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>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- druid -->
<servlet>
<servlet-name>DruidStatServlet</servlet-name>
<servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
<init-param>
<param-name>loginUsername</param-name>
<param-value>druid</param-value>
</init-param>
<init-param>
<param-name>loginPassword</param-name>
<param-value>druid</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DruidStatServlet</servlet-name>
<url-pattern>/sys/druid/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>DruidWebStatFilter</filter-name>
<filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class>
<init-param>
<param-name>exclusions</param-name>
<param-value>*.js,*.css,*.jpg,*.png,*.ico,*.gif,/sys/druid/*</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>DruidWebStatFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
5.2.6:spring-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:annotation-config />
<!-- 启动注解驱动的spring mvc 功能 -->
<mvc:annotation-driven/>
<!-- 启动包扫描功能 -->
<context:component-scan base-package="org.alan.permissionSystem.controller" />
<context:component-scan base-package="org.alan.permissionSystem.service" />
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
<bean id="jsonView" class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
5.2.7: 1.html
5.2.8: settings.properties
#db.driverClassName=com.mysql.jdbc.Driver
db.driverClassName=com.mysql.cj.jdbc.Driver
db.url=jdbc:mysql://localhost:3306/permissionsystem?useUnicode=true&characterEncoding=UTF-8
db.username=
db.password=
5.2.9:mybatis-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="safeRowBoundsEnabled" value="true"/>
<setting name="cacheEnabled" value="false" />
<setting name="useGeneratedKeys" value="true" />
</settings>
<!--<typeAliases>-->
<!---->
<!--</typeAliases>-->
<!--<plugins>-->
<!--<plugin interceptor=""></plugin>-->
<!--</plugins>-->
<!--<typeHandlers>-->
<!---->
<!--</typeHandlers>-->
</configuration>
5.2.10:logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>
<!--<appender name="permission" class="ch.qos.logback.core.rolling.RollingFileAppender">-->
<!--<file>${catalina.home}/logs/permission.log</file>-->
<!--<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">-->
<!--<FileNamePattern>${catalina.home}/logs/permission.%d{yyyy-MM-dd}.log.gz</FileNamePattern>-->
<!--</rollingPolicy>-->
<!--<layout class="ch.qos.logback.classic.PatternLayout">-->
<!--<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>-->
<!--</layout>-->
<!--</appender>-->
<!---->
<!--<logger name="xxx" level="INFO">-->
<!--<appender-ref ref="permission"/>-->
<!--</logger>-->
<!-- TRACE < DEBUG < INFO < WARN < ERROR -->
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
5.2.11:applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.alibaba.com/schema/stat http://www.alibaba.com/schema/stat.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath:settings.properties</value>
</list>
</property>
</bean>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="driverClassName" value="${db.driverClassName}" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
<property name="initialSize" value="3" />
<property name="minIdle" value="3" />
<property name="maxActive" value="20" />
<property name="maxWait" value="60000" />
<property name="filters" value="stat,wall" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:mybatis-config.xml" />
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath:mapper/*.xml" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="org.alan.permissionSystem.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
<!-- tx -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- druid -->
<bean id="stat-filter" class="com.alibaba.druid.filter.stat.StatFilter">
<property name="slowSqlMillis" value="3000" />
<property name="logSlowSql" value="true" />
<property name="mergeSql" value="true" />
</bean>
<bean id="wall-filter" class="com.alibaba.druid.wall.WallFilter">
<property name="dbType" value="mysql" />
</bean>
</beans>
5.2.12:TestMapper.xml
5.2.13:TestDao
5.2.14:TestController
5.2.15:环境相关配置
F:\SoftCode\Tomcat\apache-tomcat-8.5.60-windows-x64\apache-tomcat-8.5.60\bin\catalina.bat run
[2023-06-07 12:18:03,378] Artifact PermissionSystemNew:war exploded: Waiting for server connection to start artifact deployment...
Using CATALINA_BASE: "C:\Users\Alan_Liu\AppData\Local\JetBrains\IntelliJIdea2023.1\tomcat\f943056d-edf2-40f2-948f-dfeb77cbbdd7"
Using CATALINA_HOME: "F:\SoftCode\Tomcat\apache-tomcat-8.5.60-windows-x64\apache-tomcat-8.5.60"
Using CATALINA_TMPDIR: "F:\SoftCode\Tomcat\apache-tomcat-8.5.60-windows-x64\apache-tomcat-8.5.60\temp"
Using JRE_HOME: "E:\SoftWare\Develop_software\Java\Oracle_Jdk\jdk1.8.0_271"
Using CLASSPATH: "F:\SoftCode\Tomcat\apache-tomcat-8.5.60-windows-x64\apache-tomcat-8.5.60\bin\bootstrap.jar;F:\SoftCode\Tomcat\apache-tomcat-8.5.60-windows-x64\apache-tomcat-8.5.60\bin\tomcat-juli.jar"
Using CATALINA_OPTS: ""
07-Jun-2023 00:18:07.338 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server.服务器版本: Apache Tomcat/8.5.60
07-Jun-2023 00:18:07.343 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 服务器构建: Nov 12 2020 17:31:55 UTC
07-Jun-2023 00:18:07.343 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 服务器版本号: 8.5.60.0
07-Jun-2023 00:18:07.343 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 操作系统名称: Windows 10
07-Jun-2023 00:18:07.343 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS.版本: 10.0
07-Jun-2023 00:18:07.343 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 架构: amd64
07-Jun-2023 00:18:07.343 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java 环境变量: E:\SoftWare\Develop_software\Java\Oracle_Jdk\jdk1.8.0_271\jre
07-Jun-2023 00:18:07.344 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java虚拟机版本: 1.8.0_271-b09
07-Jun-2023 00:18:07.344 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM.供应商: Oracle Corporation
07-Jun-2023 00:18:07.344 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\Users\Alan_Liu\AppData\Local\JetBrains\IntelliJIdea2023.1\tomcat\f943056d-edf2-40f2-948f-dfeb77cbbdd7
07-Jun-2023 00:18:07.344 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: F:\SoftCode\Tomcat\apache-tomcat-8.5.60-windows-x64\apache-tomcat-8.5.60
07-Jun-2023 00:18:07.344 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djava.util.logging.config.file=C:\Users\Alan_Liu\AppData\Local\JetBrains\IntelliJIdea2023.1\tomcat\f943056d-edf2-40f2-948f-dfeb77cbbdd7\conf\logging.properties
07-Jun-2023 00:18:07.345 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
07-Jun-2023 00:18:07.345 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dcom.sun.management.jmxremote=
07-Jun-2023 00:18:07.345 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dcom.sun.management.jmxremote.port=1069
07-Jun-2023 00:18:07.345 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dcom.sun.management.jmxremote.ssl=false
07-Jun-2023 00:18:07.345 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dcom.sun.management.jmxremote.password.file=C:\Users\Alan_Liu\AppData\Local\JetBrains\IntelliJIdea2023.1\tomcat\f943056d-edf2-40f2-948f-dfeb77cbbdd7\jmxremote.password
07-Jun-2023 00:18:07.345 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dcom.sun.management.jmxremote.access.file=C:\Users\Alan_Liu\AppData\Local\JetBrains\IntelliJIdea2023.1\tomcat\f943056d-edf2-40f2-948f-dfeb77cbbdd7\jmxremote.access
07-Jun-2023 00:18:07.346 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djava.rmi.server.hostname=127.0.0.1
07-Jun-2023 00:18:07.346 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djdk.tls.ephemeralDHKeySize=2048
07-Jun-2023 00:18:07.346 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
07-Jun-2023 00:18:07.346 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dignore.endorsed.dirs=
07-Jun-2023 00:18:07.346 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dcatalina.base=C:\Users\Alan_Liu\AppData\Local\JetBrains\IntelliJIdea2023.1\tomcat\f943056d-edf2-40f2-948f-dfeb77cbbdd7
07-Jun-2023 00:18:07.347 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dcatalina.home=F:\SoftCode\Tomcat\apache-tomcat-8.5.60-windows-x64\apache-tomcat-8.5.60
07-Jun-2023 00:18:07.347 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djava.io.tmpdir=F:\SoftCode\Tomcat\apache-tomcat-8.5.60-windows-x64\apache-tomcat-8.5.60\temp
07-Jun-2023 00:18:07.347 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent 使用APR版本[1.7.0]加载了基于APR的Apache Tomcat本机库[1.2.25]。
07-Jun-2023 00:18:07.347 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR功能:IPv6[true]、sendfile[true]、accept filters[false]、random[true]。
07-Jun-2023 00:18:07.348 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL配置:useAprConnector[false],useOpenSSL[true]
07-Jun-2023 00:18:07.362 信息 [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL成功初始化 [OpenSSL 1.1.1g 21 Apr 2020]
07-Jun-2023 00:18:07.772 信息 [main] org.apache.coyote.AbstractProtocol.init 初始化协议处理器 ["http-nio-8080"]
07-Jun-2023 00:18:07.795 信息 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
07-Jun-2023 00:18:07.820 信息 [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1229 ms
07-Jun-2023 00:18:07.879 信息 [main] org.apache.catalina.core.StandardService.startInternal 正在启动服务[Catalina]
07-Jun-2023 00:18:07.879 信息 [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.60
07-Jun-2023 00:18:07.908 信息 [main] org.apache.coyote.AbstractProtocol.start 开始协议处理句柄["http-nio-8080"]
07-Jun-2023 00:18:07.942 信息 [main] org.apache.catalina.startup.Catalina.start Server startup in 121 ms
Connected to server
[2023-06-07 12:18:08,112] Artifact PermissionSystemNew:war exploded: Artifact is being deployed, please wait...
07-Jun-2023 00:18:17.377 信息 [RMI TCP Connection(2)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars 至少有一个JAR被扫描用于TLD但尚未包含TLD。 为此记录器启用调试日志记录,以获取已扫描但未在其中找到TLD的完整JAR列表。 在扫描期间跳过不需要的JAR可以缩短启动时间和JSP编译时间。
07-Jun-2023 00:18:17.547 信息 [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.context.ContextLoader.initWebApplicationContext Root WebApplicationContext: initialization started
07-Jun-2023 00:18:17.882 信息 [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.context.support.XmlWebApplicationContext.prepareRefresh Refreshing Root WebApplicationContext: startup date [Wed Jun 07 00:18:17 CST 2023]; root of context hierarchy
07-Jun-2023 00:18:17.914 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [F:\SoftCode\Tomcat\apache-tomcat-8.5.60-windows-x64\apache-tomcat-8.5.60\webapps\manager]
07-Jun-2023 00:18:18.114 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Web应用程序目录[F:\SoftCode\Tomcat\apache-tomcat-8.5.60-windows-x64\apache-tomcat-8.5.60\webapps\manager]的部署已在[199]毫秒内完成
07-Jun-2023 00:18:18.339 信息 [RMI TCP Connection(2)-127.0.0.1] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from class path resource [applicationContext.xml]
2023-06-07 00:18:25.987 [RMI TCP Connection(2)-127.0.0.1] ERROR com.alibaba.druid.pool.DruidDataSource - testWhileIdle is true, validationQuery not set
2023-06-07 00:18:29.774 [RMI TCP Connection(2)-127.0.0.1] INFO com.alibaba.druid.pool.DruidDataSource - {dataSource-1} inited
07-Jun-2023 00:18:31.330 信息 [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.context.ContextLoader.initWebApplicationContext Root WebApplicationContext: initialization completed in 13782 ms
[2023-06-07 12:18:31,439] Artifact PermissionSystemNew:war exploded: Artifact is deployed successfully
[2023-06-07 12:18:31,439] Artifact PermissionSystemNew:war exploded: Deploy took 23,327 milliseconds
07-Jun-2023 00:18:48.770 信息 [http-nio-8080-exec-6] org.springframework.web.servlet.DispatcherServlet.initServletBean FrameworkServlet 'spring': initialization started
07-Jun-2023 00:18:48.790 信息 [http-nio-8080-exec-6] org.springframework.web.context.support.XmlWebApplicationContext.prepareRefresh Refreshing WebApplicationContext for namespace 'spring-servlet': startup date [Wed Jun 07 00:18:48 CST 2023]; parent: Root WebApplicationContext
07-Jun-2023 00:18:48.792 信息 [http-nio-8080-exec-6] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-servlet.xml]
07-Jun-2023 00:18:51.610 信息 [http-nio-8080-exec-6] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.register Mapped "{[/test/hello]}" onto public java.lang.String org.alan.permissionSystem.controller.TestController.hello()
07-Jun-2023 00:18:53.520 信息 [http-nio-8080-exec-6] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.initControllerAdviceCache Looking for @ControllerAdvice: WebApplicationContext for namespace 'spring-servlet': startup date [Wed Jun 07 00:18:48 CST 2023]; parent: Root WebApplicationContext
07-Jun-2023 00:18:53.918 信息 [http-nio-8080-exec-6] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.initControllerAdviceCache Looking for @ControllerAdvice: WebApplicationContext for namespace 'spring-servlet': startup date [Wed Jun 07 00:18:48 CST 2023]; parent: Root WebApplicationContext
07-Jun-2023 00:18:54.220 信息 [http-nio-8080-exec-6] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.register Mapped "{[/test/hello]}" onto public java.lang.String org.alan.permissionSystem.controller.TestController.hello()
07-Jun-2023 00:18:54.605 信息 [http-nio-8080-exec-6] org.springframework.web.servlet.DispatcherServlet.initServletBean FrameworkServlet 'spring': initialization completed in 5834 ms
2023-06-07 00:18:54.729 [http-nio-8080-exec-6] INFO org.alan.permissionSystem.controller.TestController - hello
5.3:测试控制层 编写
5.5:第一次测试启动
5.6:完整代码下载
https://gitee.com/Alan2022/PermissionSystemNew.git
https://gitee.com/Alan2022/permissionSystem.git
六:项目准备与核心辅助工具类开发
6.1:核心类生成---> Mybatis Generator
6.1.1:generator.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!-- 数据库驱动包位置 -->
<classPathEntry location="F:/SoftCode/Idea202301_WorkSpace/PermissionSystemNew/generator/mysql-connector-j-8.0.32.jar" /> <!-- 1 -->
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- 数据库链接URL、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/permissionsystem?characterEncoding=UTF-8" userId="root" password="123456"> <!-- 2 -->
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 生成模型的包名和位置 --> <!-- 3 -->
<javaModelGenerator targetPackage="org.alan.permissionSystem.model" targetProject="F:/SoftCode/Idea202301_WorkSpace/PermissionSystemNew/generator/src">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成的映射文件包名和位置 --> <!-- 4 -->
<sqlMapGenerator targetPackage="org.alan.permissionSystem.mapper" targetProject="F:/SoftCode/Idea202301_WorkSpace/PermissionSystemNew/generator/src">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 生成DAO的包名和位置 --> <!-- 5 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="org.alan.permissionSystem.dao" targetProject="F:/SoftCode/Idea202301_WorkSpace/PermissionSystemNew/generator/src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 要生成那些表(更改tableName和domainObjectName就可以) --><!-- 6 -->
<table tableName="sys_user" domainObjectName="SysUser" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_dept" domainObjectName="SysDept" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_acl" domainObjectName="SysAcl" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_acl_module" domainObjectName="SysAclModule" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_role" domainObjectName="SysRole" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_role_acl" domainObjectName="SysRoleAcl" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_role_user" domainObjectName="SysRoleUser" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_log" domainObjectName="SysLog" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
</context>
</generatorConfiguration>
6.1.2:命令生成对应的代码文件
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
PS F:\SoftCode\Idea202301_WorkSpace\PermissionSystemNew> cd .\generator\
PS F:\SoftCode\Idea202301_WorkSpace\PermissionSystemNew\generator> java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite
Existing file F:\SoftCode\Idea202301_WorkSpace\PermissionSystemNew\generator\src\org\alan\permissionSystem\model\SysUser.java was overwritten
Existing file F:\SoftCode\Idea202301_WorkSpace\PermissionSystemNew\generator\src\org\alan\permissionSystem\dao\SysUserMapper.java was overwritten
Existing file F:\SoftCode\Idea202301_WorkSpace\PermissionSystemNew\generator\src\org\alan\permissionSystem\model\SysRole.java was overwritten
Existing file F:\SoftCode\Idea202301_WorkSpace\PermissionSystemNew\generator\src\org\alan\permissionSystem\dao\SysRoleMapper.java was overwritten
Existing file F:\SoftCode\Idea202301_WorkSpace\PermissionSystemNew\generator\src\org\alan\permissionSystem\model\SysRoleUser.java was overwritten
Existing file F:\SoftCode\Idea202301_WorkSpace\PermissionSystemNew\generator\src\org\alan\permissionSystem\dao\SysRoleUserMapper.java was overwritten
MyBatis Generator finished successfully, there were warnings.
PS F:\SoftCode\Idea202301_WorkSpace\PermissionSystemNew\generator>
生成结果:
6.2:项目接口定义:json,page
6.2.1:项目代码结构
6.2.2:JsonData
package org.alan.permissionSystem.common;
import lombok.Getter;
import lombok.Setter;
import java.util.HashMap;
import java.util.Map;
/**
*
* Json 信息及结构的封装类
*
*
*/
@Getter
@Setter
public class JsonData {
private boolean ret; //返回结果
private String msg;//返回消息
private Object data;//返回数据
public JsonData(boolean ret) {
this.ret = ret;
}
/**
* 返回成功时结果
* @param object
* @param msg
* @return
*/
public static JsonData success(Object object, String msg) {
JsonData jsonData = new JsonData(true);
jsonData.data = object;
jsonData.msg = msg;
return jsonData;
}
/**
* 返回成功时,无消息内容
* @param object
* @return
*/
public static JsonData success(Object object) {
JsonData jsonData = new JsonData(true);
jsonData.data = object;
return jsonData;
}
public static JsonData success() {
return new JsonData(true);
}
/**
* 返回失败时:失败信息
* @param msg
* @return
*/
public static JsonData fail(String msg) {
JsonData jsonData = new JsonData(false);
jsonData.msg = msg;
return jsonData;
}
/**
*
* @return
*/
public Map<String, Object> toMap() {
HashMap<String, Object> result = new HashMap<String, Object>();
result.put("ret", ret);
result.put("msg", msg);
result.put("data", data);
return result;
}
}
6.2.3:SpringExceptionResolver
package org.alan.permissionSystem.common;
import lombok.extern.slf4j.Slf4j;
import org.alan.permissionSystem.exception.ParamException;
import org.alan.permissionSystem.exception.PermissionException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* 全局异常类:
*
* 需要引入jar的pom包:
* <!-- jsp api -->
* <dependency>
* <groupId>org.apache.tomcat</groupId>
* <artifactId>jsp-api</artifactId>
* <version>6.0.36</version>
* </dependency>
*
*/
@Slf4j
public class SpringExceptionResolver implements HandlerExceptionResolver {
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
String url = request.getRequestURL().toString();
ModelAndView mv;
String defaultMsg = "System error"; //默认异常
// 这里我们要求项目中所有请求json数据,都使用.json结尾
if (url.endsWith(".json")) {
if (ex instanceof PermissionException || ex instanceof ParamException) {
JsonData result = JsonData.fail(ex.getMessage());
mv = new ModelAndView("jsonView", result.toMap());
} else {
log.error("unknown json exception, url:" + url, ex);
JsonData result = JsonData.fail(defaultMsg);
mv = new ModelAndView("jsonView", result.toMap());
}
} else if (url.endsWith(".page")){ // 这里我们要求项目中所有请求page页面,都使用.page结尾
log.error("unknown page exception, url:" + url, ex);
JsonData result = JsonData.fail(defaultMsg);
mv = new ModelAndView("exception", result.toMap());
} else {
log.error("unknow exception, url:" + url, ex);
JsonData result = JsonData.fail(defaultMsg);
mv = new ModelAndView("jsonView", result.toMap());
}
return mv;
}
}
6.2.4:ParamException
package org.alan.permissionSystem.exception;
/**
* 自定义异常:
*
*
*/
public class ParamException extends RuntimeException {
public ParamException() {
super();
}
public ParamException(String message) {
super(message);
}
public ParamException(String message, Throwable cause) {
super(message, cause);
}
public ParamException(Throwable cause) {
super(cause);
}
protected ParamException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
6.2.5:PermissionException
package org.alan.permissionSystem.exception;
/**
* 自定义异常:
*
*
*
*/
public class PermissionException extends RuntimeException {
public PermissionException() {
super();
}
public PermissionException(String message) {
super(message);
}
public PermissionException(String message, Throwable cause) {
super(message, cause);
}
public PermissionException(Throwable cause) {
super(cause);
}
protected PermissionException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
6.2.6:exception.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>500</title>
<jsp:include page="/common/backend_common.jsp"/>
</head>
<body class="no-skin" youdao="bind" style="background: white">
<div class="main-content-inner">
<div class="page-content">
<!-- /.ace-settings-container -->
<div class="row">
<div class="col-xs-12">
<!-- PAGE CONTENT BEGINS -->
<div class="error-container">
<div class="well">
<h1 class="grey lighter smaller">
<span class="blue bigger-125">
<i class="ace-icon fa fa-random"></i>
500
</span>
服务器内部错误
</h1>
<hr>
<h3 class="lighter smaller">
我们正在修复它
<i class="ace-icon fa fa-wrench icon-animated-wrench bigger-125"></i>
</h3>
<div class="space"></div>
<div>
<h4 class="lighter smaller">与此同时, 可以尝试以下:</h4>
<ul class="list-unstyled spaced inline bigger-110 margin-15">
<li>
<i class="ace-icon fa fa-hand-o-right blue"></i>
阅读FAQ
</li>
<li>
<i class="ace-icon fa fa-hand-o-right blue"></i>
联系管理员,说明问题
</li>
</ul>
</div>
<hr>
<div class="space"></div>
<div class="center">
<a href="javascript:history.back()" class="btn btn-grey">
<i class="ace-icon fa fa-arrow-left"></i>
上一页
</a>
<a href="#" class="btn btn-primary">
<i class="ace-icon fa fa-tachometer"></i>
Dashboard
</a>
</div>
</div>
</div>
<!-- PAGE CONTENT ENDS -->
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.page-content -->
</div>
</body>
</html>
6.2.7: pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.alan.permissionSystem</groupId>
<artifactId>PermissionSystemNew</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>PermissionSystemNew Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<springframework.version>4.3.10.RELEASE</springframework.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${springframework.version}</version>
</dependency>
<!--Spring MVC + Spring web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${springframework.version}</version>
</dependency>
<!-- mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.0</version>
</dependency>
<!-- druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.20</version>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.32</version>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.12</version>
</dependency>
<!-- Jackson -->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-guava</artifactId>
<version>2.5.3</version>
</dependency>
<!-- logback -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.8</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.22</version>
</dependency>
<!-- jsp api -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>jsp-api</artifactId>
<version>6.0.36</version>
</dependency>
</dependencies>
<build>
<finalName>PermissionSystemNew</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
6.2.8:spring-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:annotation-config />
<!-- 启动注解驱动的spring mvc 功能 -->
<mvc:annotation-driven/>
<!-- 启动包扫描功能 -->
<context:component-scan base-package="org.alan.permissionSystem.controller" />
<context:component-scan base-package="org.alan.permissionSystem.service" />
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />
<!--配置全局异常-->
<bean class="org.alan.permissionSystem.common.SpringExceptionResolver" />
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
<bean id="jsonView" class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
6.2.9:TtestController
package org.alan.permissionSystem.controller;
import lombok.extern.slf4j.Slf4j;
import org.alan.permissionSystem.common.JsonData;
import org.apache.ibatis.exceptions.PersistenceException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/test")
@Slf4j
public class TestController {
@RequestMapping("/hello1")
@ResponseBody
public String hello1() {
log.info("hello");
return "hello, permission";
}
@RequestMapping("/hello.json")
@ResponseBody
public JsonData hello() {
log.info("hello");
return JsonData.success( "hello, permission");
}
@RequestMapping("/helloThrow.json")
@ResponseBody
public JsonData helloThrow() {
log.info("hello");
throw new PersistenceException("test exception");
}
@RequestMapping("/helloThrowRun.json")
@ResponseBody
public JsonData helloThrowRun() {
log.info("hello");
throw new RuntimeException("test exception");
}
}
6.2.10:验证请求
正常成功启动:
20230604
为人:谦逊、激情、博学、审问、慎思、明辨、 笃行
学问:纸上得来终觉浅,绝知此事要躬行
为事:工欲善其事,必先利其器。
态度:道阻且长,行则将至;行而不辍,未来可期
.....................................................................
------- 桃之夭夭,灼灼其华。之子于归,宜其室家。 ---------------
------- 桃之夭夭,有蕡其实。之子于归,宜其家室。 ---------------
------- 桃之夭夭,其叶蓁蓁。之子于归,宜其家人。 ---------------
=====================================================================
* 博客文章部分截图及内容来自于学习的书本及相应培训课程以及网络其他博客,仅做学习讨论之用,不做商业用途。