【问题标题】:Versioning through content negotiation in mvc通过 mvc 中的内容协商进行版本控制
【发布时间】:2020-11-18 03:42:11
【问题描述】:

我有两个 get API 具有相同的请求、路径和响应,其中一个已经存在,另一个是新创建的。

  @GET
  @Path("/{id}/export")
  public Response exportVersion1(@PathParam("id") String id, @QueryParam("format") final String format)

  @GET
  @Path("/{id}/export")
  @Consumes({"application/vnd.com.abc.v2+json"})
  public Response exportVersion2(@PathParam("id") String id, @QueryParam("format") final String format)

在将内容类型指定为 application/vnd.com.abc.v2+json 时,我可以调用第二个 API,但如果没有指定内容类型,那么也会调用第二个 API。

我想将第一个设为默认值,并且不想更改/添加它,因为它绑定到客户端使用的 UI。我只能对第二个API进行更改,请提出任何建议。

【问题讨论】:

    标签: java spring rest web-services model-view-controller


    【解决方案1】:

    您可以设置默认内容类型。对于春季 5,这将是:

    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer.defaultContentType(MediaType.TEXT_PLAIN); 
    }
    

    【讨论】:

      猜你喜欢
      • 2016-03-12
      • 2020-07-10
      • 1970-01-01
      • 1970-01-01
      • 2016-01-05
      • 1970-01-01
      • 1970-01-01
      • 2012-05-07
      • 2015-06-29
      相关资源
      最近更新 更多