Java 由于我的SpringBoot应用程序,Swigger UI不显示每个端点需要2个查询参数
我的Spring boot应用程序所有端点都需要2个查询参数(Java 由于我的SpringBoot应用程序,Swigger UI不显示每个端点需要2个查询参数,java,spring,spring-boot,query-parameters,webjars,Java,Spring,Spring Boot,Query Parameters,Webjars,我的Spring boot应用程序所有端点都需要2个查询参数(http://localhost:myapplcation/getAll?pid=1101&token=jdu191092kj11)所有端点都按预期工作。 但是,如果我传递2个查询参数,我就可以看到api招摇过市(http://localhost:8080/v2/api-docs?pid=1101&token=jdu191092kj11) 这个招摇过市的用户界面有问题。。无显示http://localhost:8080/swagger
http://localhost:myapplcation/getAll?pid=1101&token=jdu191092kj11
)所有端点都按预期工作。
但是,如果我传递2个查询参数,我就可以看到api招摇过市(http://localhost:8080/v2/api-docs?pid=1101&token=jdu191092kj11
)
这个招摇过市的用户界面有问题。。无显示<代码>http://localhost:8080/swagger-ui.html
我如何解决这个问题
代码如下:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import springfox.documentation.builders.ApiInfoBuilder;
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;
import static springfox.documentation.builders.PathSelectors.regex;
@Configuration
@EnableSwagger2
public class SwaggerConfig extends WebMvcConfigurationSupport {
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.springframework.controllers"))
.paths(regex("/product.*"))
.build()
.apiInfo(metaData());
}
private ApiInfo metaData() {
return new ApiInfoBuilder()
.title("Spring Boot REST API")
.description("\"Spring Boot REST API for Online Store\"")
.version("1.0.0")
.license("Apache License Version 2.0")
.licenseUrl("https://www.apache.org/licenses/LICENSE-2.0\"")
.contact(new Contact("John Thompson", "https://springframework.com", "john@springfrmework.com"))
.build();
}
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
@RestController
公共类EmployeeController{
@Autowired
private EmployeeService employeeService;
@PostMapping("/admin/empproperties")
public @ResponseBody ResponseEntity<Employee> addNeeEmp(@RequestParam String fname, @RequestParam String sname) {
Employee emp = new Employee();
emp.setParam(fname);
emp.setValue(sname);
emp = employeeService.save(emp);
return new ResponseEntity<Employee>(emp, new HttpHeaders(), HttpStatus.OK);
}
@GetMapping("/admin/empproperties")
public ResponseEntity<List<Employee>> allEmployees(){
List<Employee> list = employeeService.findAll();
return new ResponseEntity<List<Employee>>(list, new HttpHeaders(), HttpStatus.OK);
}
@Autowired
私人雇员服务;
@后期映射(“/admin/empproperties”)
public@ResponseBody ResponseEntity addNeeEmp(@RequestParam String fname,@RequestParam String sname){
员工emp=新员工();
emp.setParam(fname);
环境管理设定值(sname);
emp=employeeService.save(emp);
返回新的ResponseEntity(emp,new-HttpHeaders(),HttpStatus.OK);
}
@GetMapping(“/admin/empproperties”)
公众响应全体员工(){
List=employeeService.findAll();
返回新的ResponseEntity(列表,新的HttpHeaders(),HttpStatus.OK);
}
}在正则表达式中添加产品。*但在url路径中没有产品术语 让我们把它简单化,看看它是否像下面那样工作
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(metaData())
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.paths(PathSelectors.any())
.build();
}
你能分享一下你对控制器的定义吗?是的,我也添加了控制器部分。。你能建议一下吗