第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在 spring 控制器中使用枚舉作為參數(shù),該控制器使用“spring”

如何在 spring 控制器中使用枚舉作為參數(shù),該控制器使用“spring”

長風(fēng)秋雁 2023-06-04 17:37:29
假設(shè)我有一個(gè)用枚舉模式定義的參數(shù):paths:  /echo:    get:      parameters:      - name: someEnum        in: query        required: true        schema:          type: string          enum: [A, B, C]      responses:        200:          description: Success          content:            text/plain:              schema:                type: stringSwagger codegen 為語言生成以下 Java 接口spring:    @ApiOperation(value = "", nickname = "echoGet", notes = "", response = String.class, tags={  })    @ApiResponses(value = {         @ApiResponse(code = 200, message = "Success", response = String.class) })    @RequestMapping(value = "/echo",        produces = { "text/plain" },         method = RequestMethod.GET)    default ResponseEntity<String> echoGet(@NotNull @ApiParam(value = "", required = true, allowableValues = "A, B, C") @Valid @RequestParam(value = "someEnum", required = true) String someEnum) {        if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {        } else {            log.warn("ObjectMapper or HttpServletRequest not configured in default EchoApi interface so no example is generated");        }        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);    }someEnum生成接口的類型是字符串。如何用具有“A”、“B”、“C”值的 Java 枚舉替換它?
查看完整描述

2 回答

?
絕地?zé)o雙

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超4個(gè)贊

將命名類型添加到模式并使用它:


paths:

  /echo:

    get:

      parameters:

        - name: someEnum

          in: query

          required: true

          schema:

            $ref: '#/components/schemas/MyEnum'

      responses:

        200:

          description: Success

          content:

            text/plain:

              schema:

                type: string

components:

  schemas:

    MyEnum:

      type: string

      enum: [A,B,C]


查看完整回答
反對(duì) 回復(fù) 2023-06-04
?
LEATH

TA貢獻(xiàn)1936條經(jīng)驗(yàn) 獲得超7個(gè)贊

在部分中定義您的枚舉架構(gòu)components/schemas,并$ref從參數(shù)定義中定義它,如下所示。在這種情況下,Swagger Codegen 會(huì)將枚舉生成為實(shí)際的 Java 枚舉。


openapi: 3.0.0

...


paths:

  /echo:

    get:

      parameters:

      - name: someEnum

        in: query

        required: true

        schema:

          $ref: '#/components/schemas/MyEnum'

      ...


components:

  schemas:

    MyEnum:

      type: string

      enum: [A, B, C]


查看完整回答
反對(duì) 回復(fù) 2023-06-04
  • 2 回答
  • 0 關(guān)注
  • 202 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)