当前位置: 首页 > 知识库问答 >
问题:

Swagger UI没有因为My SpringBoot Applcation而感到不快每个endpoint需要2个查询参数

冯良才
2023-03-14

我的Spring Boot应用程序所有endpoint需要2个查询参数(http://localhost: myApplcation/getAll?PID=1101

这个招摇过市的用户界面有问题。。无显示<代码>http://localhost:8080/swagger-用户界面。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);

}

}

共有1个答案

翟淇
2023-03-14

在正则表达式中添加产品。*但是在url路径中没有产品术语。

让我们简单一点,看看是否像下面这样工作

 @Bean
    public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(metaData())
         .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
        .paths(PathSelectors.any())
        .build();
    }
 类似资料:
  • 问题内容: 运行此代码时出现4个错误,这些错误将用户的电子邮件地址添加到名为的表中称为的数据库中。 $ con = new mysqli(’localhost’,’root’,’‘,’ecommerce’); 错误是这样的: 警告:mysqli_query()至少需要2个参数,第27行给出1个 第27行: $ query = mysqli_query(“ SELECT * FROM subscri

  • 我现在在大学学习数据库,在我的项目中,我有3个表:、和 联赛(leagueId,leagueName) 团队(teamId,teamName) 具有(leagueId,teamId,year)

  • 当尝试ViewChild时,我会得到错误。错误为“未提供'opts'的参数。” @ViewChild都给出了错误。 ts(11,2):错误TS2554:应为2个参数,但得到1。

  • 我有一个使用. NET 6 Web API的应用程序。一旦用户登录到应用程序,关于该用户的基于小上下文的信息被附加到查询参数。 API中AuthPolicy的一部分是,当调用endpoint时,这些查询参数必须存在,即使该endpoint没有使用它们。 例如,此 终结点具有在请求正文中传递的实际输入,但 AuthPolicy 要求查询参数存在,即使未使用它也是如此。 有效EX: 无效的EX: 有没

  • 我有这样的疑问: 第一个ORDER BY子句有个错误。 错误是: 我不明白为什么。这个查询在Postgres中运行良好。 有人能帮我理解为什么会出现这个错误,以及如何修复它吗? 谢谢 //edit:我是这样尝试我的代码的(在KebabArchitmer的建议下) 我也犯了同样的错误。