avatar

目录
bootdo已实现(2)

1.用户管理

点击用户管理 进入页面 页面加载成功时发生了什么

Code
1
2
sys/user
UserController

01:获取部门tree的数据

url

Code
1
/system/sysDept/tree	json返回tree,反映部门上下级关系

sql

Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
-- ----------------------------
-- Table structure for `sys_dept`
-- ----------------------------
DROP TABLE IF EXISTS `sys_dept`;
CREATE TABLE `sys_dept` (
`dept_id` bigint(20) NOT NULL AUTO_INCREMENT,
`parent_id` bigint(20) DEFAULT NULL COMMENT '上级部门ID,一级部门为0',
`name` varchar(50) DEFAULT NULL COMMENT '部门名称',
`order_num` int(11) DEFAULT NULL COMMENT '排序',
`del_flag` tinyint(4) DEFAULT '0' COMMENT '是否删除 -1:已删除 0:正常',
PRIMARY KEY (`dept_id`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8 COMMENT='部门管理';

-- ----------------------------
-- Records of sys_dept
-- ----------------------------
INSERT INTO `sys_dept` VALUES ('6', '0', '研发部', '1', '1');
INSERT INTO `sys_dept` VALUES ('7', '6', '研發一部', '1', '1');
INSERT INTO `sys_dept` VALUES ('8', '6', '研发二部', '2', '1');
INSERT INTO `sys_dept` VALUES ('9', '0', '销售部', '2', '1');
INSERT INTO `sys_dept` VALUES ('10', '9', '销售一部', '1', '1');
INSERT INTO `sys_dept` VALUES ('11', '0', '产品部', '3', '1');
INSERT INTO `sys_dept` VALUES ('12', '11', '产品一部', '1', '1');
INSERT INTO `sys_dept` VALUES ('13', '0', '测试部', '5', '1');
INSERT INTO `sys_dept` VALUES ('14', '13', '测试一部', '1', '1');
INSERT INTO `sys_dept` VALUES ('15', '13', '测试二部', '2', '1');

逆向工程

BuildTree.build

DeptService.getTree

java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@Override
public Tree<DeptDO> getTree() {
List<DeptDO> sysDepts = deptDao.list(new HashMap<String, Object>());
List<Tree<DeptDO>> trees = new ArrayList<Tree<DeptDO>>();
for (DeptDO sysDept : sysDepts){
Tree<DeptDO> tree = new Tree<DeptDO>();
tree.setId(sysDept.getDeptId().toString());
tree.setParentId(sysDept.getParentId().toString());
tree.setText(sysDept.getName());
Map<String,Object> state = new HashMap<String, Object>();
state.put("opened",true);
tree.setState(state);
trees.add(tree);
}
Tree<DeptDO> t = BuildTree.build(trees);
return t;
}

controller

java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
@Controller
@RequestMapping("system/sysDept")
public class DeptController {

@Autowired
private DeptService deptService;

@GetMapping("tree")
@ResponseBody
public Tree<DeptDO> tree(){
Tree<DeptDO> tree = deptService.getTree();
return tree;
}
}

测试:/system/sysDept/tree

json
1
{"id":"-1","text":"顶级节点","state":{"opened":true},"checked":true,"attributes":null,"children":[{"id":"13","text":"测试部","state":{"opened":true},"checked":false,"attributes":null,"children":[{"id":"15","text":"测试二部","state":{"opened":true},"checked":false,"attributes":null,"children":[],"parentId":"13","hasParent":true,"hasChildren":false},{"id":"14","text":"测试一部","state":{"opened":true},"checked":false,"attributes":null,"children":[],"parentId":"13","hasParent":true,"hasChildren":false}],"parentId":"0","hasParent":false,"hasChildren":true},{"id":"11","text":"产品部","state":{"opened":true},"checked":false,"attributes":null,"children":[{"id":"12","text":"产品一部","state":{"opened":true},"checked":false,"attributes":null,"children":[],"parentId":"11","hasParent":true,"hasChildren":false}],"parentId":"0","hasParent":false,"hasChildren":true},{"id":"9","text":"销售部","state":{"opened":true},"checked":false,"attributes":null,"children":[{"id":"10","text":"销售一部","state":{"opened":true},"checked":false,"attributes":null,"children":[],"parentId":"9","hasParent":true,"hasChildren":false}],"parentId":"0","hasParent":false,"hasChildren":true},{"id":"6","text":"研发部","state":{"opened":true},"checked":false,"attributes":null,"children":[{"id":"8","text":"研发二部","state":{"opened":true},"checked":false,"attributes":null,"children":[],"parentId":"6","hasParent":true,"hasChildren":false},{"id":"7","text":"研發一部","state":{"opened":true},"checked":false,"attributes":null,"children":[],"parentId":"6","hasParent":true,"hasChildren":false}],"parentId":"0","hasParent":false,"hasChildren":true}],"parentId":"","hasParent":false,"hasChildren":true}

02:列出用户信息

url

Code
1
2
/sys/user/list
传入参数params是键值对,用Map接收,包括:limit offset name(按名称查询) deptId

sql 测试数据

逆向工程的 mapper.list 可以条件查询,排序,分页

dao service 逆向生成

Query封装查询参数

PageUtils分装分页数据

controller

java
1
2
3
4
5
6
7
8
9
10
11
@GetMapping("/list")
@ResponseBody
PageUtils list(@RequestParam Map<String,Object> params){

//query继承map,以key value形式封装所有查询参数
Query query = new Query(params);
List<UserDO> sysUserList = userService.list(query);
int count = userService.count(query);//查询符合条件的总条数
PageUtils pageUtil = new PageUtils(sysUserList,count);
return pageUtil;
}

测试

postman

测分页 limit offset

​ 问题:password以密文形式暴露(原版也是)

测试 name deptId

​ name不是模糊查询,是全名匹配

问题:total查的是总记录(原版也是)

03:添加

04:单个删除

05:批量删除选中

06:编辑(修改用户信息)

07:修改密码

08:底栏分页信息

文章作者: Machine
文章链接: https://machine4869.gitee.io/2018/07/22/15328488958205/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 哑舍
打赏
  • 微信
    微信
  • 支付宝
    支付宝

评论