mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	update swagger升级3.0.2
This commit is contained in:
		
							
								
								
									
										15
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								pom.xml
									
									
									
									
									
								
							@@ -20,7 +20,8 @@
 | 
			
		||||
        <java.version>1.8</java.version>
 | 
			
		||||
        <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
 | 
			
		||||
        <druid.version>1.2.4</druid.version>
 | 
			
		||||
        <knife4j.version>2.0.8</knife4j.version>
 | 
			
		||||
        <knife4j.version>3.0.2</knife4j.version>
 | 
			
		||||
        <swagger-annotations.version>1.5.22</swagger-annotations.version>
 | 
			
		||||
        <fastjson.version>1.2.75</fastjson.version>
 | 
			
		||||
        <poi.version>4.1.2</poi.version>
 | 
			
		||||
        <velocity.version>1.7</velocity.version>
 | 
			
		||||
@@ -56,6 +57,18 @@
 | 
			
		||||
                <groupId>com.github.xiaoymin</groupId>
 | 
			
		||||
                <artifactId>knife4j-spring-boot-starter</artifactId>
 | 
			
		||||
                <version>${knife4j.version}</version>
 | 
			
		||||
                <exclusions>
 | 
			
		||||
                    <exclusion>
 | 
			
		||||
                        <artifactId>swagger-annotations</artifactId>
 | 
			
		||||
                        <groupId>io.swagger</groupId>
 | 
			
		||||
                    </exclusion>
 | 
			
		||||
                </exclusions>
 | 
			
		||||
            </dependency>
 | 
			
		||||
 | 
			
		||||
            <dependency>
 | 
			
		||||
                <groupId>io.swagger</groupId>
 | 
			
		||||
                <artifactId>swagger-annotations</artifactId>
 | 
			
		||||
                <version>${swagger-annotations.version}</version>
 | 
			
		||||
            </dependency>
 | 
			
		||||
			
 | 
			
		||||
            <!-- excel工具 -->
 | 
			
		||||
 
 | 
			
		||||
@@ -24,11 +24,6 @@
 | 
			
		||||
            <optional>true</optional> <!-- 表示依赖不会传递 -->
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.github.xiaoymin</groupId>
 | 
			
		||||
            <artifactId>knife4j-spring-boot-starter</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
         <!-- Mysql驱动包 -->
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>mysql</groupId>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,166 +0,0 @@
 | 
			
		||||
package com.ruoyi.web.controller.tool;
 | 
			
		||||
 | 
			
		||||
import cn.hutool.core.lang.Validator;
 | 
			
		||||
import com.ruoyi.common.core.controller.BaseController;
 | 
			
		||||
import com.ruoyi.common.core.domain.AjaxResult;
 | 
			
		||||
import io.swagger.annotations.*;
 | 
			
		||||
import org.springframework.web.bind.annotation.*;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.LinkedHashMap;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * swagger 用户测试方法
 | 
			
		||||
 * 
 | 
			
		||||
 * @author ruoyi
 | 
			
		||||
 */
 | 
			
		||||
@Api("用户信息管理")
 | 
			
		||||
@RestController
 | 
			
		||||
@RequestMapping("/test/user")
 | 
			
		||||
public class TestController extends BaseController
 | 
			
		||||
{
 | 
			
		||||
    private final static Map<Integer, UserEntity> users = new LinkedHashMap<Integer, UserEntity>();
 | 
			
		||||
    {
 | 
			
		||||
        users.put(1, new UserEntity(1, "admin", "admin123", "15888888888"));
 | 
			
		||||
        users.put(2, new UserEntity(2, "ry", "admin123", "15666666666"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation("获取用户列表")
 | 
			
		||||
    @GetMapping("/list")
 | 
			
		||||
    public AjaxResult userList()
 | 
			
		||||
    {
 | 
			
		||||
        List<UserEntity> userList = new ArrayList<UserEntity>(users.values());
 | 
			
		||||
        return AjaxResult.success(userList);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation("获取用户详细")
 | 
			
		||||
    @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path")
 | 
			
		||||
    @GetMapping("/{userId}")
 | 
			
		||||
    public AjaxResult getUser(@PathVariable Integer userId)
 | 
			
		||||
    {
 | 
			
		||||
        if (!users.isEmpty() && users.containsKey(userId))
 | 
			
		||||
        {
 | 
			
		||||
            return AjaxResult.success(users.get(userId));
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            return AjaxResult.error("用户不存在");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation("新增用户")
 | 
			
		||||
    @ApiImplicitParam(name = "userEntity", value = "新增用户信息", dataType = "UserEntity")
 | 
			
		||||
    @PostMapping("/save")
 | 
			
		||||
    public AjaxResult save(UserEntity user)
 | 
			
		||||
    {
 | 
			
		||||
        if (Validator.isNull(user) || Validator.isNull(user.getUserId()))
 | 
			
		||||
        {
 | 
			
		||||
            return AjaxResult.error("用户ID不能为空");
 | 
			
		||||
        }
 | 
			
		||||
        return AjaxResult.success(users.put(user.getUserId(), user));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation("更新用户")
 | 
			
		||||
    @ApiImplicitParam(name = "userEntity", value = "新增用户信息", dataType = "UserEntity")
 | 
			
		||||
    @PutMapping("/update")
 | 
			
		||||
    public AjaxResult update(UserEntity user)
 | 
			
		||||
    {
 | 
			
		||||
        if (Validator.isNull(user) || Validator.isNull(user.getUserId()))
 | 
			
		||||
        {
 | 
			
		||||
            return AjaxResult.error("用户ID不能为空");
 | 
			
		||||
        }
 | 
			
		||||
        if (users.isEmpty() || !users.containsKey(user.getUserId()))
 | 
			
		||||
        {
 | 
			
		||||
            return AjaxResult.error("用户不存在");
 | 
			
		||||
        }
 | 
			
		||||
        users.remove(user.getUserId());
 | 
			
		||||
        return AjaxResult.success(users.put(user.getUserId(), user));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation("删除用户信息")
 | 
			
		||||
    @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path")
 | 
			
		||||
    @DeleteMapping("/{userId}")
 | 
			
		||||
    public AjaxResult delete(@PathVariable Integer userId)
 | 
			
		||||
    {
 | 
			
		||||
        if (!users.isEmpty() && users.containsKey(userId))
 | 
			
		||||
        {
 | 
			
		||||
            users.remove(userId);
 | 
			
		||||
            return AjaxResult.success();
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            return AjaxResult.error("用户不存在");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ApiModel("用户实体")
 | 
			
		||||
class UserEntity
 | 
			
		||||
{
 | 
			
		||||
    @ApiModelProperty("用户ID")
 | 
			
		||||
    private Integer userId;
 | 
			
		||||
 | 
			
		||||
    @ApiModelProperty("用户名称")
 | 
			
		||||
    private String username;
 | 
			
		||||
 | 
			
		||||
    @ApiModelProperty("用户密码")
 | 
			
		||||
    private String password;
 | 
			
		||||
 | 
			
		||||
    @ApiModelProperty("用户手机")
 | 
			
		||||
    private String mobile;
 | 
			
		||||
 | 
			
		||||
    public UserEntity()
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public UserEntity(Integer userId, String username, String password, String mobile)
 | 
			
		||||
    {
 | 
			
		||||
        this.userId = userId;
 | 
			
		||||
        this.username = username;
 | 
			
		||||
        this.password = password;
 | 
			
		||||
        this.mobile = mobile;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Integer getUserId()
 | 
			
		||||
    {
 | 
			
		||||
        return userId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setUserId(Integer userId)
 | 
			
		||||
    {
 | 
			
		||||
        this.userId = userId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getUsername()
 | 
			
		||||
    {
 | 
			
		||||
        return username;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setUsername(String username)
 | 
			
		||||
    {
 | 
			
		||||
        this.username = username;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getPassword()
 | 
			
		||||
    {
 | 
			
		||||
        return password;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setPassword(String password)
 | 
			
		||||
    {
 | 
			
		||||
        this.password = password;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getMobile()
 | 
			
		||||
    {
 | 
			
		||||
        return mobile;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setMobile(String mobile)
 | 
			
		||||
    {
 | 
			
		||||
        this.mobile = mobile;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -5,6 +5,8 @@ import com.ruoyi.common.config.RuoYiConfig;
 | 
			
		||||
import io.swagger.annotations.ApiOperation;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Value;
 | 
			
		||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
 | 
			
		||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 | 
			
		||||
import org.springframework.context.annotation.Bean;
 | 
			
		||||
import org.springframework.context.annotation.Configuration;
 | 
			
		||||
import springfox.documentation.builders.ApiInfoBuilder;
 | 
			
		||||
@@ -14,7 +16,7 @@ import springfox.documentation.service.*;
 | 
			
		||||
import springfox.documentation.spi.DocumentationType;
 | 
			
		||||
import springfox.documentation.spi.service.contexts.SecurityContext;
 | 
			
		||||
import springfox.documentation.spring.web.plugins.Docket;
 | 
			
		||||
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
 | 
			
		||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
@@ -25,8 +27,10 @@ import java.util.List;
 | 
			
		||||
 * @author Lion Li
 | 
			
		||||
 */
 | 
			
		||||
@Configuration
 | 
			
		||||
@EnableSwagger2WebMvc
 | 
			
		||||
@EnableSwagger2
 | 
			
		||||
@EnableKnife4j
 | 
			
		||||
@ConditionalOnClass({Docket.class, ApiInfoBuilder.class})
 | 
			
		||||
@ConditionalOnProperty(prefix = "swagger", value = "enable", matchIfMissing = true)
 | 
			
		||||
public class SwaggerConfig {
 | 
			
		||||
    /**
 | 
			
		||||
     * 系统基础配置
 | 
			
		||||
@@ -34,12 +38,6 @@ public class SwaggerConfig {
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private RuoYiConfig ruoyiConfig;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 是否开启swagger
 | 
			
		||||
     */
 | 
			
		||||
    @Value("${swagger.enabled}")
 | 
			
		||||
    private boolean enabled;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 设置请求的统一前缀
 | 
			
		||||
     */
 | 
			
		||||
@@ -70,8 +68,6 @@ public class SwaggerConfig {
 | 
			
		||||
    @Bean
 | 
			
		||||
    public Docket createRestApi() {
 | 
			
		||||
        return new Docket(DocumentationType.SWAGGER_2)
 | 
			
		||||
                // 是否启用Swagger
 | 
			
		||||
                .enable(enabled)
 | 
			
		||||
                // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
 | 
			
		||||
                .apiInfo(apiInfo())
 | 
			
		||||
                // 设置哪些接口暴露给Swagger展示
 | 
			
		||||
@@ -85,15 +81,14 @@ public class SwaggerConfig {
 | 
			
		||||
                .build()
 | 
			
		||||
                /* 设置安全模式,swagger可以设置访问token */
 | 
			
		||||
                .securitySchemes(securitySchemes())
 | 
			
		||||
                .securityContexts(securityContexts())
 | 
			
		||||
                .pathMapping(pathMapping);
 | 
			
		||||
                .securityContexts(securityContexts());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 安全模式,这里指定token通过Authorization头请求头传递
 | 
			
		||||
     */
 | 
			
		||||
    private List<ApiKey> securitySchemes() {
 | 
			
		||||
        List<ApiKey> apiKeyList = new ArrayList<ApiKey>();
 | 
			
		||||
    private List<SecurityScheme> securitySchemes() {
 | 
			
		||||
        List<SecurityScheme> apiKeyList = new ArrayList<SecurityScheme>();
 | 
			
		||||
        apiKeyList.add(new ApiKey("Authorization", "Authorization", "header"));
 | 
			
		||||
        return apiKeyList;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -131,6 +131,16 @@
 | 
			
		||||
            <artifactId>spring-boot-admin-starter-client</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.github.xiaoymin</groupId>
 | 
			
		||||
            <artifactId>knife4j-spring-boot-starter</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>io.swagger</groupId>
 | 
			
		||||
            <artifactId>swagger-annotations</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
    </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -23,11 +23,6 @@
 | 
			
		||||
            <artifactId>ruoyi-common</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.github.xiaoymin</groupId>
 | 
			
		||||
            <artifactId>knife4j-spring-boot-starter</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
    </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
		Reference in New Issue
	
	Block a user