乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Swagger序列化LocalDateTime的優(yōu)化

       wwq圖書(shū)世界 2019-11-19

      Swagger 序列化 LocalDateTime 的優(yōu)化

      wusq Java基礎(chǔ) 六月 20, 2019

      2,268 total views, 12 views today

      Swagger UI 的頁(yè)面中,請(qǐng)求的數(shù)據(jù)類(lèi)型會(huì)被序列化成字符串,顯示在 Model Schema 中。

      但是,Java8 中的 LocalDateTime 類(lèi)型會(huì)被序列化成很復(fù)雜的字符串,如下圖。

      解決的辦法其實(shí)很簡(jiǎn)單,在 Swagger 的配置中,添加 directModelSubstitute 方法的代碼

      Java
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      @Configuration
      @EnableSwagger2
      public class Swagger2Config {
      @Bean
      public Docket createRestApi() {
      return new Docket(DocumentationType.SWAGGER_2)
      .directModelSubstitute(LocalDateTime.class, Date.class)
      .directModelSubstitute(LocalDate.class, String.class)
      .directModelSubstitute(LocalTime.class, String.class)
      .directModelSubstitute(ZonedDateTime.class, String.class)
      .apiInfo(apiInfo()).select()
      .apis(RequestHandlerSelectors.basePackage("com.abcd.restful")).paths(PathSelectors.any()).build();
      }
      private ApiInfo apiInfo() {
      return new ApiInfoBuilder().title("Platform API").contact("abcd").version("1.0").build();
      }
      }

      directModelSubstitute 方法顧名思義就是在序列化的時(shí)候用一個(gè)類(lèi)型代替一個(gè)類(lèi)型。

      上面的例子,LocalDateTime 類(lèi)型用 Date 類(lèi)型替代,LocalDate 類(lèi)型直接用 String 類(lèi)型替代,這樣就避免的 Swagger 原生的序列化方法把 LocalDateTime 序列化的很復(fù)雜。效果如下:

      原創(chuàng)文章,轉(zhuǎn)載請(qǐng)注明出處!http://www./swagger序列化localdatetime的優(yōu)化/

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類(lèi)似文章 更多