小编Dev*_*Dev的帖子

@JsonCreator 不适用于 Spring MVC 中的 @RequestParams

@JsonCreator 不反序列化枚举类型的 @RequestParam

我正在开发一个 Spring 应用程序,其中控制器正在接收 Spring 绑定到包装器对象的请求参数列表。其中一个参数是 enum 类型,我通过某个属性名称接收它。

Endpoint example: http://localhost:8080/searchCustomers?lastName=Smith&country=Netherlands

@RequestMapping(value = "/search/customers", method = RequestMethod.GET)
public CustomerList searchCustomers(@Valid CustomerSearchCriteria searchCriteria)

public class CustomerSearchCriteria {

    private String lastName;
    private Country country;
}

public enum Country {

    GB("United Kingdom"),
    NL("Netherlands")

    private String countryName;

    Country(String countryName) {
        countryName = countryName;
    }

    @JsonCreator
    public static Country fromCountryName(String countryName) {

        for(Country country : Country.values()) {

            if(country.getCountryName().equalsIgnoreCase(countryName)) {

                return country;
            }
        }
        return null;
    }

    @JsonValue
    public String toCountryName() {

        return countryName; …
Run Code Online (Sandbox Code Playgroud)

java enums json spring-mvc spring-boot

7
推荐指数
1
解决办法
852
查看次数

Google Places API 结果与 Google 地图不匹配

我正在尝试使用 Google Places API 查找给定邮政编码附近的餐馆。我在 API 调用中使用的纬度/经度与 Google 地图网站返回的纬度/经度相同,但餐厅列表几乎有 80% 不同。

我的 API 调用如下所示

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=51.4949254,-0.0138559&type=restaurant&key=API_KEY&radius=1000

我该怎么做才能从 Google Places API 返回更准确的结果(最好与从maps.google.com 返回的列表相同)?

google-maps google-places-api

5
推荐指数
1
解决办法
1129
查看次数