簡體   English   中英

在REST中使用Google Appengine datastore.key時出錯

[英]Error using google appengine datastore.key with REST

我正在使用AppEngine數據存儲作為持久層構建REST應用程序。 但是,在解析它們的鍵以創建新條目時,在資源類中使用com.google.appengine.api.datastore.Key時遇到問題。

錯誤消息如下:嚴重:缺少方法public com.acolsolutions.loyaltycard.persistence.entities.Card com.acolsolutions.loyaltycard.resources.CardResource.findByKey(com.google.appengine.api.datastore.Key)的依賴項index 0 SEVERE:方法,公共com.acolsolutions.loyaltycard.persistence.entities.Card com.acolsolutions.loyaltycard.resources.CardResource.findByKey(com.google.appengine.api.dat astore.Key),帶有資源GET注釋, com.acolsolutions.loyaltycard.resources.CardResource類無法識別為有效的資源方法。

問題似乎發生在這里。 似乎無法將值轉換為Key類型:


    public Card findByKey(@PathParam("key") Key key) {
    ...
    }

我的REST類如下所示:import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.acolsolutions.loyaltycard.dataobjects.CardDAO;
import com.acolsolutions.loyaltycard.persistence.entities.Card;
import com.google.appengine.api.datastore.Key;

@Path("/cards")
public class CardResource {
CardDAO dao = new CardDAO();

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public List<Card> findAll() {
    System.out.println("findAll");
    return dao.findAll("creationDate desc");
}

@GET
@Path("search/{query}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public List<Card> findByName(@PathParam("query") String query) {
    System.out.println("findByName: " + query);
    return dao.findByName(query, "creationDate desc");
}


@GET
@Path("{key}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Card findByKey(@PathParam("key") Key key) {
    //System.out.println("findByKey " + key.toString());
    return dao.findByKey(key);
}

有人可以告訴我要做什么才能做什么?

謝謝克里斯

您可以嘗試將參數更改為String而不是Key,然后使用com.google.appengine.api.datastore.KeyFactory.stringToKey(String stringKey)來獲取Key。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM