当前位置:   article > 正文

knife4j(UI)文档-代码用例_如何修改knife4j的script前端请求代码

如何修改knife4j的script前端请求代码

示例1

  1. /**
  2. * 导出用户
  3. */
  4. @SneakyThrows
  5. @GetMapping("export-user")
  6. @ApiOperationSupport(order = 13)
  7. @ApiOperation(value = "导出用户", notes = "传入user")
  8. public void exportUser(@ApiIgnore @RequestParam Map<String, Object> user, BladeUser bladeUser, HttpServletResponse response) {
  9. QueryWrapper<User> queryWrapper = Condition.getQueryWrapper(user, User.class);
  10. if (!SecureUtil.isAdministrator()){
  11. queryWrapper.lambda().eq(User::getTenantId, bladeUser.getTenantId());
  12. }
  13. queryWrapper.lambda().eq(User::getIsDeleted, BladeConstant.DB_NOT_DELETED);
  14. List<UserExcel> list = userService.exportUser(queryWrapper);
  15. response.setContentType("application/vnd.ms-excel");
  16. response.setCharacterEncoding(Charsets.UTF_8.name());
  17. String fileName = URLEncoder.encode("用户数据导出", Charsets.UTF_8.name());
  18. response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
  19. EasyExcel.write(response.getOutputStream(), UserExcel.class).sheet("用户数据表").doWrite(list);
  20. }

示例2

  1. /**
  2. * 查询单条
  3. */
  4. @ApiOperationSupport(order =2)
  5. @ApiOperation(value = "查看详情", notes = "传入id")
  6. @GetMapping("/info")
  7. public R<UserVO> info(BladeUser user) {
  8. User detail = userService.getById(user.getUserId());
  9. return R.data(UserWrapper.build().entityVO(detail));
  10. }

示例3

  1. /**
  2. * 用户列表
  3. */
  4. @GetMapping("/list")
  5. @ApiImplicitParams({
  6. @ApiImplicitParam(name = "account", value = "账号名", paramType = "query", dataType = "string"),
  7. @ApiImplicitParam(name = "realName", value = "姓名", paramType = "query", dataType = "string")
  8. })
  9. @ApiOperationSupport(order = 3)
  10. @ApiOperation(value = "列表", notes = "传入account和realName")
  11. public R<IPage<UserVO>> list(@ApiIgnore @RequestParam Map<String, Object> user, Query query, BladeUser bladeUser) {
  12. QueryWrapper<User> queryWrapper = Condition.getQueryWrapper(user, User.class);
  13. IPage<User> pages = userService.page(Condition.getPage(query), (!bladeUser.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID)) ? queryWrapper.lambda().eq(User::getTenantId, bladeUser.getTenantId()) : queryWrapper);
  14. return R.data(UserWrapper.build().pageVO(pages));
  15. }

示例4

  1. /**
  2. * 新增或修改
  3. */
  4. @PostMapping("/submit")
  5. @ApiOperationSupport(order = 4)
  6. @ApiOperation(value = "新增或修改", notes = "传入User")
  7. public R submit(@Valid @RequestBody User user) {
  8. return R.status(userService.submit(user));
  9. }

示例5

  1. /**
  2. * 修改
  3. */
  4. @PostMapping("/update")
  5. @ApiOperationSupport(order = 5)
  6. @ApiOperation(value = "修改", notes = "传入User")
  7. public R update(@Valid @RequestBody User user) {
  8. return R.status(userService.updateById(user));
  9. }

示例6

  1. /**
  2. * 删除
  3. */
  4. @PostMapping("/remove")
  5. @ApiOperationSupport(order = 6)
  6. @ApiOperation(value = "删除", notes = "传入id集合")
  7. public R remove(@RequestParam String ids) {
  8. return R.status(userService.deleteLogic(Func.toLongList(ids)));
  9. }

示例7

  1. /**
  2. * 设置菜单权限
  3. *
  4. * @param userIds
  5. * @param roleIds
  6. * @return
  7. */
  8. @PostMapping("/grant")
  9. @ApiOperationSupport(order = 7)
  10. @ApiOperation(value = "权限设置", notes = "传入roleId集合以及menuId集合")
  11. public R grant(@ApiParam(value = "userId集合", required = true) @RequestParam String userIds,
  12. @ApiParam(value = "roleId集合", required = true) @RequestParam String roleIds) {
  13. boolean temp = userService.grant(userIds, roleIds);
  14. return R.status(temp);
  15. }

示例8

  1. @PostMapping("/reset-password")
  2. @ApiOperationSupport(order = 8)
  3. @ApiOperation(value = "初始化密码", notes = "传入userId集合")
  4. public R resetPassword(@ApiParam(value = "userId集合", required = true) @RequestParam String userIds) {
  5. boolean temp = userService.resetPassword(userIds);
  6. return R.status(temp);
  7. }

示例9

  1. /**
  2. * 修改密码
  3. *
  4. * @param oldPassword
  5. * @param newPassword
  6. * @param newPassword1
  7. * @return
  8. */
  9. @PostMapping("/update-password")
  10. @ApiOperationSupport(order = 9)
  11. @ApiOperation(value = "修改密码", notes = "传入密码")
  12. public R updatePassword(BladeUser user, @ApiParam(value = "旧密码", required = true) @RequestParam String oldPassword,
  13. @ApiParam(value = "新密码", required = true) @RequestParam String newPassword,
  14. @ApiParam(value = "新密码", required = true) @RequestParam String newPassword1) {
  15. boolean temp = userService.updatePassword(user.getUserId(), oldPassword, newPassword, newPassword1);
  16. return R.status(temp);
  17. }

示例10

  1. /**
  2. * 用户列表
  3. *
  4. * @param user
  5. * @return
  6. */
  7. @GetMapping("/user-list")
  8. @ApiOperationSupport(order = 10)
  9. @ApiOperation(value = "用户列表", notes = "传入user")
  10. public R<List<User>> userList(User user) {
  11. List<User> list = userService.list(Condition.getQueryWrapper(user));
  12. return R.data(list);
  13. }

示例11

  1. /**
  2. * 导出模板
  3. */
  4. @SneakyThrows
  5. @GetMapping("export-template")
  6. @ApiOperationSupport(order = 14)
  7. @ApiOperation(value = "导出模板")
  8. public void exportUser(HttpServletResponse response) {
  9. List<UserExcel> list = new ArrayList<>();
  10. response.setContentType("application/vnd.ms-excel");
  11. response.setCharacterEncoding(Charsets.UTF_8.name());
  12. String fileName = URLEncoder.encode("用户数据模板", Charsets.UTF_8.name());
  13. response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
  14. EasyExcel.write(response.getOutputStream(), UserExcel.class).sheet("用户数据表").doWrite(list);
  15. }

示例12

  1. /**
  2. * 分页
  3. */
  4. @GetMapping("/list")
  5. @ApiImplicitParams({
  6. @ApiImplicitParam(name = "category", value = "公告类型", paramType = "query", dataType = "integer"),
  7. @ApiImplicitParam(name = "title", value = "公告标题", paramType = "query", dataType = "string")
  8. })
  9. @ApiOperationSupport(order = 2)
  10. @ApiOperation(value = "分页", notes = "传入notice")
  11. public R<IPage<NoticeVO>> list(@ApiIgnore @RequestParam Map<String, Object> notice, Query query) {
  12. IPage<Notice> pages = noticeService.page(Condition.getPage(query), Condition.getQueryWrapper(notice, Notice.class));
  13. return R.data(NoticeWrapper.build().pageVO(pages));
  14. }

示例13

  1. /**
  2. * 新增
  3. */
  4. @PostMapping("/save")
  5. @ApiOperationSupport(order = 3)
  6. @ApiOperation(value = "新增", notes = "传入notice")
  7. public R save(@RequestBody Notice notice) {
  8. return R.status(noticeService.save(notice));
  9. }

示例14

  1. /**
  2. * 修改
  3. */
  4. @PostMapping("/update")
  5. @ApiOperationSupport(order = 4)
  6. @ApiOperation(value = "修改", notes = "传入notice")
  7. public R update(@RequestBody Notice notice) {
  8. return R.status(noticeService.updateById(notice));
  9. }

示例15

  1. /**
  2. * 新增或修改
  3. */
  4. @PostMapping("/submit")
  5. @ApiOperationSupport(order = 5)
  6. @ApiOperation(value = "新增或修改", notes = "传入notice")
  7. public R submit(@RequestBody Notice notice) {
  8. return R.status(noticeService.saveOrUpdate(notice));
  9. }

示例16

  1. /**
  2. * 删除
  3. */
  4. @PostMapping("/remove")
  5. @ApiOperationSupport(order = 6)
  6. @ApiOperation(value = "逻辑删除", notes = "传入notice")
  7. public R remove(@ApiParam(value = "主键集合") @RequestParam String ids) {
  8. boolean temp = noticeService.deleteLogic(Func.toLongList(ids));
  9. return R.status(temp);
  10. }

示例17

  1. /**
  2. * 新增或修改
  3. */
  4. @PostMapping("/submit")
  5. @ApiOperationSupport(order = 4)
  6. @ApiOperation(value = "新增或修改", notes = "传入dict")
  7. public R submit(@Valid @RequestBody Dict dict) {
  8. return R.status(dictService.submit(dict));
  9. }

示例18

  1. /**
  2. * 删除
  3. */
  4. @PostMapping("/remove")
  5. @CacheEvict(cacheNames = {DICT_LIST, DICT_VALUE}, allEntries = true)
  6. @ApiOperationSupport(order = 5)
  7. @ApiOperation(value = "删除", notes = "传入ids")
  8. public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
  9. return R.status(dictService.removeByIds(Func.toLongList(ids)));
  10. }

示例19

  1. /**
  2. * 获取字典
  3. *
  4. * @return
  5. */
  6. @GetMapping("/dictionary")
  7. @ApiOperationSupport(order = 6)
  8. @ApiOperation(value = "获取字典", notes = "获取字典")
  9. public R<List<Dict>> dictionary(String code) {
  10. List<Dict> tree = dictService.getList(code);
  11. return R.data(tree);
  12. }

示例20

  1. /**
  2. * 新增或修改
  3. */
  4. @PostMapping("/submit")
  5. @PreAuth(RoleConstant.HAS_ROLE_ADMIN)
  6. @ApiOperationSupport(order = 3)
  7. @ApiOperation(value = "新增或修改", notes = "传入menu")
  8. public R submit(@Valid @RequestBody Menu menu) {
  9. return R.status(menuService.saveOrUpdate(menu));
  10. }

示例21

  1. /**
  2. * 删除
  3. */
  4. @PostMapping("/remove")
  5. @PreAuth(RoleConstant.HAS_ROLE_ADMIN)
  6. @ApiOperationSupport(order = 4)
  7. @ApiOperation(value = "删除", notes = "传入ids")
  8. public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
  9. return R.status(menuService.removeByIds(Func.toLongList(ids)));
  10. }

示例22

  1. /**
  2. * 前端菜单数据
  3. */
  4. @GetMapping("/routes")
  5. @ApiOperationSupport(order = 5)
  6. @ApiOperation(value = "前端菜单数据", notes = "前端菜单数据")
  7. public R<List<MenuVO>> routes(BladeUser user) {
  8. List<MenuVO> list = menuService.routes(user.getRoleId());
  9. return R.data(list);
  10. }

示例23

  1. /**
  2. * 前端按钮数据
  3. */
  4. @GetMapping("/buttons")
  5. @ApiOperationSupport(order = 6)
  6. @ApiOperation(value = "前端按钮数据", notes = "前端按钮数据")
  7. public R<List<MenuVO>> buttons(BladeUser user) {
  8. List<MenuVO> list = menuService.buttons(user.getRoleId());
  9. return R.data(list);
  10. }

示例24

  1. /**
  2. * 获取权限分配树形结构
  3. */
  4. @GetMapping("/grant-tree")
  5. @ApiOperationSupport(order = 8)
  6. @ApiOperation(value = "权限分配树形结构", notes = "权限分配树形结构")
  7. public R<List<MenuVO>> grantTree(BladeUser user) {
  8. return R.data(menuService.grantTree(user));
  9. }

示例25

  1. /**
  2. * 获取权限分配树形结构
  3. */
  4. @GetMapping("/role-tree-keys")
  5. @ApiOperationSupport(order = 9)
  6. @ApiOperation(value = "角色所分配的树", notes = "角色所分配的树")
  7. public R<List<String>> roleTreeKeys(String roleIds) {
  8. return R.data(menuService.roleTreeKeys(roleIds));
  9. }

示例26

  1. /**
  2. * 获取配置的角色权限
  3. */
  4. @GetMapping("auth-routes")
  5. @ApiOperationSupport(order = 10)
  6. @ApiOperation(value = "菜单的角色权限")
  7. public R<List<Kv>> authRoutes(BladeUser user) {
  8. return R.data(menuService.authRoutes(user));
  9. }

示例27

  1. /**
  2. * 分页 岗位表
  3. */
  4. @GetMapping("/list")
  5. @ApiOperationSupport(order = 2)
  6. @ApiOperation(value = "分页", notes = "传入post")
  7. public R<IPage<PostVO>> list(Post post, Query query) {
  8. IPage<Post> pages = postService.page(Condition.getPage(query), Condition.getQueryWrapper(post));
  9. return R.data(PostWrapper.build().pageVO(pages));
  10. }

示例28

  1. /**
  2. * 自定义分页 岗位表
  3. */
  4. @GetMapping("/page")
  5. @ApiOperationSupport(order = 3)
  6. @ApiOperation(value = "分页", notes = "传入post")
  7. public R<IPage<PostVO>> page(PostVO post, Query query) {
  8. IPage<PostVO> pages = postService.selectPostPage(Condition.getPage(query), post);
  9. return R.data(pages);
  10. }

示例29

  1. /**
  2. * 新增 岗位表
  3. */
  4. @PostMapping("/save")
  5. @ApiOperationSupport(order = 4)
  6. @ApiOperation(value = "新增", notes = "传入post")
  7. public R save(@Valid @RequestBody Post post) {
  8. return R.status(postService.save(post));
  9. }

示例30

  1. /**
  2. * 修改 岗位表
  3. */
  4. @PostMapping("/update")
  5. @ApiOperationSupport(order = 5)
  6. @ApiOperation(value = "修改", notes = "传入post")
  7. public R update(@Valid @RequestBody Post post) {
  8. return R.status(postService.updateById(post));
  9. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/93478
推荐阅读
  

闽ICP备14008679号