我想为下面的代码片段添加醒目的实现。但是找不到确切的注释来读取招摇的网址输入。
尝试使用,
@ApiOperation(httpMethod = "GET",value = "Get Value",response = String.class)
@ApiImplicitParams({@ApiImplicitParam(name="basePath",paramType = "path")
@GetMapping(value = "/**")
public String getUrlPath(HttpServletRequest request){
return request.getServletPath();
}
上面的代码没有帮助。
@GetMapping(value = "/**")
public String getUrlPath(HttpServletRequest request){
return request.getServletPath();
}
期望是通过swagger-ui获取一个URL作为输入,并返回与响应相同的内容。
答案 0 :(得分:0)
假设您的控制器如下所示:
package com.sample.controller;
@RestController
@RequestMapping
@Api(value = "GreetingsController", tags = {"Just for greetings"})
Public class GreetingsController{
@ApiOperation(httpMethod = "GET", value = "Get value",notes = "description")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK !"),
@ApiResponse(code = 500, message = "Internal Error")
})
@GetMapping(value = "/")
public String getUrlPath(HttpServletRequest request){
return request.getServletPath();
}
}
依赖性:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version> <!-- maybe there a new version -->
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version> <!-- maybe there a new version -->
</dependency>
配置:
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configurable
public class AppConfig{
public @Bean Docket restApi() {
return new Docket(DocumentationType.SWAGGER_2).groupName("GroupeName").apiInfo(apiInfo())
.select().paths(PathSelectors.regex(".*controller.*")).build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("App title").description("App description")
.termsOfServiceUrl("").license("©Licence").licenseUrl("").version("1.0").build();
}
}
Application.yml:
server:
port: 8111
servlet:
context-path: /exampleApp
访问网址:http://localhost:8111/exampleApp/swagger-ui.html