feat(添加swagger配置): swagger角色接口配置完成

master
wayn 5 years ago
parent 4870035750
commit 035d3e17d4

@ -23,6 +23,7 @@
<commons.fileupload.version>1.3.3</commons.fileupload.version>
<commons-lang3.version>3.8.1</commons-lang3.version>
<fastjson.version>1.2.58</fastjson.version>
<swagger.version>2.9.2</swagger.version>
</properties>
<dependencies>
@ -120,6 +121,7 @@
<artifactId>jedis</artifactId>
</dependency>
<!-- jwt验证 -->
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
@ -132,6 +134,27 @@
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<!-- swagger2-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<!--防止进入swagger页面报类型转换错误排除2.9.2中的引用手动增加1.5.21版本-->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.21</version>
</dependency>
<!-- swagger2-UI-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
</dependencies>
<build>

@ -0,0 +1,54 @@
package com.wayn.framework.config;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
/**
* API
*/
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
// 用来创建该API的基本信息展示在文档的页面中自定义展示的信息
.apiInfo(apiInfo())
// 设置哪些接口暴露给Swagger展示
.select()
// 扫描所有有注解的api用这种方式更灵活
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
// 扫描指定包中的swagger注解
//.apis(RequestHandlerSelectors.basePackage("com.ruoyi.project.tool.swagger"))
// 扫描所有 .apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
/**
*
*/
private ApiInfo apiInfo() {
// 用ApiInfoBuilder进行定制
return new ApiInfoBuilder()
// 设置标题
.title("标题wayn_admin管理系统_接口文档")
// 描述
.description("描述用于查看后台管理系统api接口")
// 作者信息
.contact(new Contact(WaynConfig.getName(), null, WaynConfig.getEmail()))
// 版本
.version("版本号:" + WaynConfig.getVersion())
.build();
}
}

@ -14,15 +14,15 @@ public class WaynConfig {
/**
*
*/
private String name;
private static String name;
/**
*
*/
private String version;
private static String version;
/**
*
*/
private String email;
private static String email;
public static String getUploadDir() {
return uploadDir;
@ -31,4 +31,28 @@ public class WaynConfig {
public void setUploadDir(String uploadDir) {
WaynConfig.uploadDir = uploadDir;
}
public static String getName() {
return name;
}
public void setName(String name) {
WaynConfig.name = name;
}
public static String getVersion() {
return version;
}
public void setVersion(String version) {
WaynConfig.version = version;
}
public static String getEmail() {
return email;
}
public void setEmail(String email) {
WaynConfig.email = email;
}
}

@ -7,6 +7,8 @@ import com.wayn.common.util.R;
import com.wayn.common.util.SecurityUtils;
import com.wayn.project.system.domain.SysRole;
import com.wayn.project.system.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -14,6 +16,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
@Api(value = "角色接口")
@RestController
@RequestMapping("system/role")
public class RoleController extends BaseController {
@ -21,13 +24,14 @@ public class RoleController extends BaseController {
@Autowired
private IRoleService iRoleService;
@ApiOperation(value = "角色列表", notes = "角色列表")
@GetMapping("/list")
public R list(SysRole role) {
Page<SysRole> page = getPage();
return R.success().add("page", iRoleService.listPage(page, role));
}
@ApiOperation(value = "保存用户", notes = "保存用户")
@PostMapping
public R addRole(@Validated @RequestBody SysRole role) {
if (SysConstants.NOT_UNIQUE.equals(iRoleService.checkRoleNameUnique(role))) {
@ -40,6 +44,7 @@ public class RoleController extends BaseController {
return R.result(iRoleService.insertRoleAndMenu(role));
}
@ApiOperation(value = "更新用户", notes = "更新用户")
@PutMapping
public R updateRole(@Validated @RequestBody SysRole role) {
iRoleService.checkRoleAllowed(role);
@ -52,6 +57,7 @@ public class RoleController extends BaseController {
return R.result(iRoleService.updateRoleAndMenu(role));
}
@ApiOperation(value = "更新用户状态", notes = "更新用户状态")
@PutMapping("changeStatus")
public R changeStatus(@RequestBody SysRole role) {
iRoleService.checkRoleAllowed(role);
@ -59,14 +65,15 @@ public class RoleController extends BaseController {
return R.result(iRoleService.updateById(role));
}
@ApiOperation("获取角色详细")
@GetMapping("/{roleId}")
public R getRole(@PathVariable Long roleId) {
return R.success().add("data", iRoleService.getById(roleId));
}
@ApiOperation("删除角色")
@DeleteMapping("/{roleIds}")
public R getRole(@PathVariable List<Long> roleIds) {
public R deleteRole(@PathVariable List<Long> roleIds) {
return R.success().add("data", iRoleService.deleteRoleByIds(roleIds));
}
}

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.wayn.common.base.BaseEntity;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -14,6 +15,7 @@ import java.util.List;
* sys_role
*/
@Data
@ApiModel("角色实体")
@EqualsAndHashCode(callSuper = true)
public class SysRole extends BaseEntity {

Loading…
Cancel
Save