Java mvc中通过内容协商进行版本控制
我有两个get API,它们具有相同的请求、路径和响应,其中一个已经存在,另一个是新创建的Java mvc中通过内容协商进行版本控制,java,spring,rest,web-services,model-view-controller,Java,Spring,Rest,Web Services,Model View Controller,我有两个get API,它们具有相同的请求、路径和响应,其中一个已经存在,另一个是新创建的 @GET @Path("/{id}/export") public Response exportVersion1(@PathParam("id") String id, @QueryParam("format") final String format) @GET @Path("/{id}/export"
@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进行更改,请给出建议。您可以设置默认内容类型。对于spring 5,这将是:
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.defaultContentType(MediaType.TEXT_PLAIN);
}