首页 > 解决方案 > javax.ws.rs.Produces 在 Spring 中等效

问题描述

@Produces(javax.ws.rs.core. MediaType.APPLICATION_JSON)包中是否有等效的注释,org.springframework.web.bind.annotation以免两者混用?就像我现在正在做的......

@PostMapping("/price-menu")
    @Produces(javax.ws.rs.core. MediaType.APPLICATION_JSON)
    public ResponseEntity<Currency> menus 
            (HttpServletRequest request) {
..
}

标签: javaspringrestspring-bootrestful-architecture

解决方案


@PostMapping 有一个名为produces. (https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/PostMapping.html#produces--

你可以像这样使用它:@PostMapping(path = "/price-menu", consumes = "application/json", produces = "application/json")


推荐阅读