sping boot with Swagger IU问题使用JSON作为参数

问题描述 投票:0回答:1

我正在 Spring Boot 中开发 REST api,也使用 Swagger UI。在我想要实现的端点中,一个通过位置(纬度,经度,半径距离)并查找距离小于或等于该半径的所有数据

@Tag(name = "Metadata")
@RestController
@RequestMapping("/api/v1/metadata")
public class MetadataSiteController {

    private final MetadataSiteService metadataSiteService;
    private final GeoMetadataSiteService geoMetadataSiteService;

    @Autowired
    public MetadataSiteController(MetadataSiteService metadataSiteService, GeoMetadataSiteService geoMetadataSiteService) {
        this.metadataSiteService = metadataSiteService;
        this.geoMetadataSiteService = geoMetadataSiteService;
    }

    ....

    @GetMapping(
            value = "/sites/nearby-location/test",
            consumes = MediaType.APPLICATION_JSON_VALUE,
            produces = MediaType.APPLICATION_JSON_VALUE
    )
    @ResponseBody
    public List<SiteDTO> fetchSitesLocationNear(
            @Valid
            @RequestBody
            LocationRequestDTO locationRequest
    ){
        return geoMetadataSiteService.getSitesByLocation(locationRequest);
    }
}

地点:

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Builder
public class LocationRequestDTO{

    private Double latitude;
    private Double longitude;
    private Double distance;

}

当我尝试这个端点时,我收到此错误

我不使用 jackson databind,因为它给我带来了 Swagger UI 的问题,所以我选择了这个

<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.10.1</version>
</dependency>
java json spring-boot media-type
1个回答
0
投票

尝试使用

@PostMapping
来代替
@GetMapping

© www.soinside.com 2019 - 2024. All rights reserved.