我看不到我在 Swagger-ui 中注释为 @RequestBody 的参数

问题描述 投票:0回答:1

我看不到在 POST 请求中将所需参数添加到我的微服务中的可能性。这是我的代码:

@Operation(summary = "Send a mail. It is possible to add to the mail a carbon copy and attachments.")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "Mail sent successfully "),
            @ApiResponse(responseCode = "404", description = "Something went wrong while sending the email.", content = @Content)
    })
    @PostMapping("/send")
    public void sendMailWithTemplate(@RequestBody Form form) {
        emailService.sendMail(form.getTo(), form.getCc(), form.getSubject(), form.getText(), form.getFile());
    }

这是我的 pom.xml 的依赖部分:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-mail</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>io.swagger.core.v3</groupId>
        <artifactId>swagger-models</artifactId>
        <version>2.2.20</version>
    </dependency>
    <dependency>
        <groupId>io.swagger.parser.v3</groupId>
        <artifactId>swagger-parser-v3</artifactId>
        <version>2.1.20</version>
    </dependency>
    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.1</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-boot-starter</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>jakarta.servlet</groupId>
        <artifactId>jakarta.servlet-api</artifactId>
        <version>6.1.0-M1</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

</dependencies>

我正在添加我的 swagger-ui 的视图

你能帮我一下吗?谢谢你。

我尝试用谷歌搜索答案并与chat.gpt聊天

java spring swagger-ui
1个回答
0
投票

更新 我找到了一种方法。

注解@RequestBody的导入应该是: org.springframework.web.bind.annotation.RequestBody;

至少对我来说是这样的

© www.soinside.com 2019 - 2024. All rights reserved.