Skip to content

Commit

Permalink
✨ 添加 swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
icodelife committed Jul 13, 2021
1 parent bcffd9b commit c4b33d3
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 5 deletions.
8 changes: 6 additions & 2 deletions docs/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ INSERT INTO `t_resource` VALUES (235, '字典管理', 'sysDict:manager', '/sysDi
INSERT INTO `t_resource` VALUES (236, '列表', 'sysDict:dataGrid', '/sysDict/dataGrid', 'ajax', '资源列表', 'glyphicon-th-list', 235, 0, 1, 1, 1, '2018-04-15 20:17:32', '2018-04-15 21:59:40');
INSERT INTO `t_resource` VALUES (237, '添加', 'sysDict:add', '/sysDict/add', 'ajax', '资源添加', 'glyphicon-plus', 235, 0, 1, 1, 1, '2018-04-15 20:17:32', '2018-04-15 21:32:45');
INSERT INTO `t_resource` VALUES (238, '编辑', 'sysDict:edit', '/sysDict/edit', 'ajax', '资源编辑', 'glyphicon-pencil', 235, 0, 1, 1, 1, '2018-04-15 20:17:32', '2018-04-15 21:32:55');
INSERT INTO `t_resource` VALUES (239, 'swagger', '', '/doc.html', '', NULL, 'glyphicon-send ', 221, 0, 1, 1, 0, '2021-04-12 22:57:05', '2021-07-13 22:40:13');
COMMIT;

-- ----------------------------
Expand Down Expand Up @@ -260,6 +261,7 @@ INSERT INTO `t_role_resource` VALUES (675, 1, 235);
INSERT INTO `t_role_resource` VALUES (676, 1, 236);
INSERT INTO `t_role_resource` VALUES (677, 1, 237);
INSERT INTO `t_role_resource` VALUES (678, 1, 238);
INSERT INTO `t_role_resource` VALUES (679, 1, 239);
INSERT INTO `t_role_resource` VALUES (437, 2, 1);
INSERT INTO `t_role_resource` VALUES (438, 2, 13);
INSERT INTO `t_role_resource` VALUES (439, 2, 131);
Expand All @@ -271,6 +273,7 @@ INSERT INTO `t_role_resource` VALUES (443, 2, 223);
INSERT INTO `t_role_resource` VALUES (444, 2, 224);
INSERT INTO `t_role_resource` VALUES (446, 2, 227);
INSERT INTO `t_role_resource` VALUES (447, 2, 228);
INSERT INTO `t_role_resource` VALUES (448, 2, 239);
INSERT INTO `t_role_resource` VALUES (158, 3, 1);
INSERT INTO `t_role_resource` VALUES (159, 3, 11);
INSERT INTO `t_role_resource` VALUES (164, 3, 12);
Expand Down Expand Up @@ -324,6 +327,7 @@ INSERT INTO `t_role_resource` VALUES (556, 8, 231);
INSERT INTO `t_role_resource` VALUES (557, 8, 232);
INSERT INTO `t_role_resource` VALUES (558, 8, 233);
INSERT INTO `t_role_resource` VALUES (559, 8, 234);
INSERT INTO `t_role_resource` VALUES (560, 8, 239);
COMMIT;

-- ----------------------------
Expand All @@ -347,8 +351,8 @@ CREATE TABLE `t_sys_dict` (
BEGIN;
INSERT INTO `t_sys_dict` VALUES (1, 'adminSex', '性别-男', '0', '', 0, '2018-04-21 12:45:34');
INSERT INTO `t_sys_dict` VALUES (2, 'adminSex', '性别-女', '1', '', 1, '2018-04-21 12:45:34');
INSERT INTO `t_sys_dict` VALUES (3, 'dbStatus', '数据库状态-失效', '0', '失效', 0, '2018-04-21 12:46:37');
INSERT INTO `t_sys_dict` VALUES (4, 'dbStatus', '数据库状态-正常', '1', '正常', 1, '2018-04-21 12:46:59');
INSERT INTO `t_sys_dict` VALUES (3, 'dbStatus', '数据库状态-正常', '1', '正常', 0, '2018-04-21 12:46:59');
INSERT INTO `t_sys_dict` VALUES (4, 'dbStatus', '数据库状态-失效', '0', '失效', 1, '2018-04-21 12:46:37');
INSERT INTO `t_sys_dict` VALUES (5, 'adminLocked', '锁定-否', '0', '', 0, '2018-04-21 12:50:56');
INSERT INTO `t_sys_dict` VALUES (6, 'adminLocked', '锁定-是', '1', '', 1, '2018-04-21 12:51:15');
INSERT INTO `t_sys_dict` VALUES (7, 'adminType', 'admin类型-管理员', '0', '管理员', 1, '2018-04-21 12:52:27');
Expand Down
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
<groupId>net.dreamlu</groupId>
<artifactId>mica-ip2region</artifactId>
</dependency>
<dependency>
<groupId>net.dreamlu</groupId>
<artifactId>mica-swagger</artifactId>
</dependency>
<!-- mica end -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/dreamlu/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
public void configure(WebSecurity web) {
// @formatter:off
web.ignoring().antMatchers(HttpMethod.OPTIONS, "/**")
.antMatchers("/test/**")
.antMatchers("/favicon.ico")
.antMatchers("/error")
.antMatchers("/static/**")
.antMatchers("/webjars*")
.antMatchers("/webjars/**")
.antMatchers("/captcha.jpg")
.antMatchers("/excel/**")
.antMatchers("/doc.html")
.antMatchers("/swagger-resources/**")
.antMatchers("/upload/**");
// @formatter:on
Expand Down Expand Up @@ -113,7 +113,6 @@ protected void configure(HttpSecurity http) throws Exception {
.deleteCookies("JSESSIONID", "remember-me");

http.csrf()
.ignoringAntMatchers("/druid/**", "/ueditor")
.csrfTokenRepository(new CookieCsrfTokenRepository());
// @formatter:on
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/dreamlu/system/web/AdminController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package net.dreamlu.system.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import net.dreamlu.common.annotation.SysLog;
import net.dreamlu.common.base.BaseController;
Expand All @@ -38,6 +39,7 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.ArrayList;
Expand All @@ -54,11 +56,13 @@
@Controller
@RequestMapping("/admin")
@RequiredArgsConstructor
@Api(tags = "管理员::管理")
public class AdminController extends BaseController {
private final IAdminService adminService;
private final PasswordEncoder passwordEncoder;
private final IRoleService roleService;

@ApiIgnore
@GetMapping("/editPwdPage")
@PreAuthorize("@sec.hasPermission('admin:edit:pwd')")
public String editPwdPage() {
Expand All @@ -84,6 +88,7 @@ public R<Object> editUserPwd(AuthUser user, String oldPwd, String pwd) {
return status(adminService.updateById(entity));
}

@ApiIgnore
@GetMapping("/manager")
public String manager() {
return "system/admin/adminList";
Expand All @@ -96,6 +101,7 @@ public EasyPage<AdminVO> dataGrid(AdminVO adminVO, PageVO pageVO) {
return EasyPage.of(adminVOIPage);
}

@ApiIgnore
@GetMapping("/addPage")
public String addPage() {
return "system/admin/adminAdd";
Expand Down Expand Up @@ -123,6 +129,7 @@ public R<Object> delete(Admin admin) {
return status(adminService.removeById(admin));
}

@ApiIgnore
@GetMapping("/editPage")
public String editPage(Model model, Integer id) {
Admin admin = adminService.getById(id);
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/net/dreamlu/system/web/CommonController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package net.dreamlu.system.web;

import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import net.dreamlu.common.DreamConstants;
import net.dreamlu.common.base.BaseController;
Expand All @@ -24,9 +25,11 @@
import net.dreamlu.mica.core.utils.WebUtil;
import net.dreamlu.secrity.auth.AuthUser;
import org.springframework.core.io.Resource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;

Expand All @@ -37,14 +40,17 @@
*/
@Controller
@RequiredArgsConstructor
@Api(tags = "公共::管理")
public class CommonController extends BaseController {
private final ICaptchaService captchaService;

@ApiIgnore
@GetMapping({"/", "main"})
public String index() {
return "system/main";
}

@ApiIgnore
@GetMapping("login")
public String loginView(AuthUser user) {
if (user == null) {
Expand All @@ -53,18 +59,20 @@ public String loginView(AuthUser user) {
return redirect("/main");
}

@ApiIgnore
@GetMapping("accessDenied")
public String accessDenied() {
return "system/error/accessDenied";
}

@GetMapping("captcha.jpg")
@GetMapping(value = "captcha.jpg", produces = MediaType.IMAGE_JPEG_VALUE)
public ResponseEntity<Resource> captcha(HttpServletResponse response) {
String uuid = StringUtil.getUUID();
WebUtil.setCookie(response, DreamConstants.CAPTCHA_COOKIE_NAME, uuid, -1);
return captchaService.generateResponseEntity(uuid);
}

@ApiIgnore
@GetMapping("icons.html")
public String icons() {
return "system/common/icons";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package net.dreamlu.system.web;

import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import net.dreamlu.common.annotation.SysLog;
import net.dreamlu.common.base.BaseController;
Expand All @@ -30,6 +31,7 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;
Expand All @@ -45,9 +47,11 @@
@Controller
@RequestMapping("/organization")
@RequiredArgsConstructor
@Api(tags = "组织::管理")
public class OrganizationController extends BaseController {
private final IOrganizationService organizationService;

@ApiIgnore
@GetMapping("/manager")
public String manager() {
return "system/organization/organizationList";
Expand All @@ -71,6 +75,7 @@ public List<Tree> tree() {
/**
* 添加页面
*/
@ApiIgnore
@GetMapping("/addPage")
public String addPage() {
return "system/organization/organizationAdd";
Expand Down Expand Up @@ -100,6 +105,7 @@ public R<Object> delete(Organization organization) {
/**
* 编辑
*/
@ApiIgnore
@GetMapping("/editPage")
public String editPage(Model model, Long id) {
Organization organization = organizationService.getById(id);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/net/dreamlu/system/web/ResourceController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package net.dreamlu.system.web;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import net.dreamlu.common.annotation.SysLog;
import net.dreamlu.common.base.BaseController;
Expand All @@ -32,6 +33,7 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;
Expand All @@ -47,9 +49,11 @@
@Controller
@RequestMapping("/resource")
@RequiredArgsConstructor
@Api(tags = "资源::管理")
public class ResourceController extends BaseController {
private final IResourceService resourceService;

@ApiIgnore
@GetMapping("/manager")
public String manager() {
return "system/resource/resourceList";
Expand Down Expand Up @@ -98,6 +102,7 @@ public List<Tree> tree(AuthUser authUser) {
* @param model 数据绑定
* @param pid 选中的id
*/
@ApiIgnore
@GetMapping("/addPage")
public String addPage(Model model, Long pid) {
model.addAttribute("pid", pid);
Expand Down Expand Up @@ -128,6 +133,7 @@ public R<Object> delete(Resource resource) {
/**
* 编辑页
*/
@ApiIgnore
@GetMapping("/editPage")
public String editPage(Model model, Long id) {
Resource resource = resourceService.getById(id);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/dreamlu/system/web/RoleController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import net.dreamlu.common.annotation.SysLog;
import net.dreamlu.common.base.BaseController;
Expand All @@ -34,6 +35,7 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;
Expand All @@ -49,9 +51,11 @@
@Controller
@RequestMapping("/role")
@RequiredArgsConstructor
@Api(tags = "角色::管理")
public class RoleController extends BaseController {
private final IRoleService roleService;

@ApiIgnore
@GetMapping("/manager")
public String manager() {
return "system/role/roleList";
Expand All @@ -78,6 +82,7 @@ public List<Tree> tree() {
/**
* 添加页面
*/
@ApiIgnore
@GetMapping("/addPage")
public String addPage() {
return "system/role/roleAdd";
Expand Down Expand Up @@ -108,6 +113,7 @@ public R<Object> delete(Role role) {
/**
* 编辑
*/
@ApiIgnore
@GetMapping("/editPage")
public String editPage(Model model, Long id) {
Role role = roleService.getById(id);
Expand All @@ -129,6 +135,7 @@ public R<Object> edit(@Valid Role role) {
/**
* 授权页面
*/
@ApiIgnore
@GetMapping("/grantPage")
public String grantPage(Model model, Long id) {
model.addAttribute("id", id);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/net/dreamlu/system/web/SysDictController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import net.dreamlu.common.base.BaseController;
import net.dreamlu.common.result.EasyPage;
Expand All @@ -34,6 +35,7 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.time.LocalDateTime;
Expand All @@ -50,9 +52,11 @@
@Controller
@RequestMapping("/sysDict")
@RequiredArgsConstructor
@Api(tags = "字典::管理")
public class SysDictController extends BaseController {
private final ISysDictService sysDictService;

@ApiIgnore
@GetMapping("/manager")
@PreAuthorize("@sec.hasPermission('sysDict:manager')")
public String manager() {
Expand Down Expand Up @@ -87,6 +91,7 @@ public List<SysDict> list() {
/**
* 添加页面-字典
*/
@ApiIgnore
@GetMapping("/addPage")
public String addPage() {
return "system/sysDict/sysDictAdd";
Expand All @@ -106,6 +111,7 @@ public R<Object> add(@Valid SysDict sysDict) {
/**
* 编辑-字典
*/
@ApiIgnore
@GetMapping("/editPage")
public String editPage(Model model, Integer id) {
SysDict sysDict = sysDictService.getById(id);
Expand Down
Loading

0 comments on commit c4b33d3

Please sign in to comment.