0

我用以下方法定义了一个端点:

@ApiMethod(name = "update", path = "properties/{id}", httpMethod = HttpMethod.PUT)
public void update(@Named("id") Long id, RealEstatePropertyAPI propertyAPI,
        User user) {

在客户端,我尝试了几个调用,但它们都没有填充propertyAPI服务器端的对象。创建实例时,所有字段都设置nullid.

        var jsonId = { 'id': '11'};
        var x = {"name": "Test","address": { "street": "White House"}};
        gapi.client.realestate.update(jsonId, x).execute(function(resp) {
            console.log('PropertyEdited');
            console.log(resp);
        });

或者

        var jsonId = { 'id': '11'};
        var x = {"name": "Test","address": { "street": "White House"}};
        gapi.client.realestate.update(jsonId, {'resource' : x}).execute(function(resp) {
            console.log('PropertyEdited');
            console.log(resp);
        });

Java 类:

public class RealEstatePropertyAPI {

    private Long id;
    private String name;
    private AddressAPI address;

    public RealEstatePropertyAPI() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public AddressAPI getAddress() {
        return address;
    }

    public void setAddress(AddressAPI address) {
        this.address = address;
    }

}

public class AddressAPI {

    private Long id;
    private String street;
    private String city;
    private String state;
    private String zip;
    private String country;

    public AddressAPI() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getZip() {
        return zip;
    }

    public void setZip(String zip) {
        this.zip = zip;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

}
4

1 回答 1

0

我实际上对此不确定,但您可以尝试在单个对象中传递所有参数,我的意思是用括号将参数包装起来{ },如下所示:

//var jsonId = { 'id': '11'};
var x = {"name": "Test","address": { "street": "White House"}};
gapi.client.realestate.update({'id': '11', 'resource' : x}).execute(function(resp) {
    console.log('PropertyEdited');
    console.log(resp);
});

因为实际上在您的两个请求中,您都发送了 2 个对象……
而且我认为您必须'resource'像第二个选项一样使用 POST 数据中的参数……

于 2013-08-03T17:38:15.623 回答