0

자전거라는 모델이 있습니다. 삽입하고 가져올 수 있으며, 개체를 나열 할 수 있습니다. 하지만 지금은 나머지 모든 필드를 그대로 유지하면서 Google 애플리케이션 엔진에서 Bike Object의 가격 만 업데이트하려고합니다. 그래서 나는 패치 방법을 통해 갔다. 나는 가격 만 업데이트하기 위해 Google 앱 엔진 엔드 포인트에서 패치 메소드를 사용하는 방법을 얻지 못하고있다.Google 앱 엔진 엔드 포인트에서 패치 방법을 사용하는 방법

이것은

@Entity 

공용 클래스 자전거 내 자전거 모델이다 {

@Id 
protected Long id; 

@Index 
protected String imageUrl; 

@Index 
protected String title; 

@Index 
protected String price; 

@Index 
protected String kmpl; 

@Index 
protected String cc; 

@Index 
protected String make; 


public Bike(){} 


public Bike(String s, String s1, String s2, 
String s3, String  s4,String s5) { 

    this.title = s; 
    this.cc = s1; 
    this.kmpl = s2; 
    this.price = s3; 
    this.imageUrl=s4; 
    this.make=s5; 

} 

public String getPrice() { 
    return price; 
} 

public void setPrice(String price) { 
    this.price = price; 
} 

public String getKmpl() { 
    return kmpl; 
} 

public void setKmpl(String kmpl) { 
    this.kmpl = kmpl; 
} 

public String getCc() { 
    return cc; 
} 

public void setCc(String cc) { 
    this.cc = cc; 
} 

public Long getId() { 
    return id; 
} 

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

public String getImageUrl() { 
    return imageUrl; 
} 

public void setImageUrl(String imageUrl) { 
    this.imageUrl = imageUrl; 
} 

public String getTitle() { 
    return title; 
} 

public void setTitle(String title) { 
    this.title = title; 
} 

public String getMake() { 
    return make; 
} 

public void setMake(String make) { 
    this.make = make; 
} 
} 

이 난에 패치 방법을 사용하고자하는 유사한 방법으로 내 삽입 API를

/** 
* Inserts a new {@code Bike}. 
*/ 
@ApiMethod(
     name = "insert", 
     path = "bike", 
     httpMethod = ApiMethod.HttpMethod.POST) 
public Bike insert(Bike bike) { 
    // Typically in a RESTful API a POST does not have a known ID (assuming the ID is used in the resource path). 
    // You should validate that bike.id has not been set. If the ID type is not supported by the 
    // Objectify ID generator, e.g. long or String, then you should generate the unique ID yourself prior to saving. 
    // 
    // If your client provides the ID then you should probably use PUT instead. 
    ofy().save().entity(bike).now(); 
    logger.info("Created Bike with ID: " + bike.getId()); 

    return ofy().load().entity(bike).now(); 
} 

입니다 Bike의 가격 만 업데이트하십시오.

답변

0

Google Cloud Endpoints에서 PATCH HTTP 메소드를 사용할 수 있다고 생각하지 않습니다. @ApiMethod Annotation에 대한 문서를 참조하십시오. "매개 변수로 엔티티를 가져 오는 메소드는 HttpMethod.POST를 사용해야합니다 (삽입 작업의 경우) 또는 HttpMethod.PUT (업데이트 작업) "(https://cloud.google.com/appengine/docs/java/endpoints/annotations).

은 (AN @Entity로 주석) 특정 클래스를 만들 수 (예 : 더 적은 대역폭을 사용) 완전한 "자전거"리소스 표현입니다 보내지 않도록하려면 당신이 할 수있는 일 또한 https://cloud.google.com/appengine/docs/java/endpoints/javadoc/com/google/api/server/spi/config/ApiMethod.HttpMethod

참조하는 경우에만 두 가지 필수 필드가 있습니다. 의 예를 들어 BikePrice를 호출하자

@Entity 
public class BikePrice { 

    @Id 
    protected Long id; 

    protected String price; 

당신은 다음 객관화를 통해 자전거 원래 개체를로드하고

.... 
    httpMethod = ApiMethod.HttpMethod.PUT) 
    public void updateBike(BikePrice bikePrice) { 

    Bike b = ofy().load().type(Bike.class).id(bikePrice.getId()).now(); 
    b.setPrice(bikePrice.getPrice()); 
.... 

주를 업데이트하는 (매개 변수로 BikePrice 엔티티와) 전용 엔드 포인트 방법을 만드는 것이 데이터 스토어에 BikePrice 엔티티를 저장하지 마십시오. 프런트 엔드와 App Engine간에 일종의 "컨테이너"또는 "데이터 컨베이어"로 사용됩니다.