Objectify和google云端点示例

时间:2021-01-17 23:13:14

I'm trying to find some concrete examples with google cloud end points and objectify. I've already found some with either end-points or objectify but none that combines both of them.

我试图找到谷歌云端点和客观化的一些具体例子。我已经找到了一些既有端点也有客体化,但没有一种结合它们。

1 个解决方案

#1


2  

Same problem than you when I started to learn objectify and endpoints.

当我开始学习客体化和端点时,与你相同的问题。

Here is a tuto from website (Sorry that's in french): http://blog.xebia.fr/2014/06/23/google-app-engine-cloud-endpoint-creer-notre-api-v2-et-lutiliser-avec-angularjs/

这是来自网站的tuto(抱歉,这是法语):http://blog.xebia.fr/2014/06/23/google-app-engine-cloud-endpoint-creer-notre-api-v2-et-lutiliser -avec-angularjs /

EDIT: You can find in english, this amazing website which explain in details my code below : http://rominirani.com/2014/08/26/gradle-tutorial-part-9-cloud-endpoints-persistence-android-studio/

编辑:你可以找到英文,这个惊人的网站,详细解释我的代码如下:http://rominirani.com/2014/08/26/gradle-tutorial-part-9-cloud-endpoints-persistence-android-studio /

In simple, you have to have three classes:

简单来说,你必须有三个类:

Your object :

你的对象:

@Entity
@Index

public class User {


        @Id private String num_portable; 
        private Boolean sexe;
        private int date_naissance;

        //Constructeur par défaut (Obligatoire pour Objectify)
        public User(){}

        public User (String num_portable, Boolean sexe, int date_naissance){

            this.num_portable=num_portable; //Numéro de portable user
            this.sexe=sexe; 
            this.date_naissance=date_naissance; 

        }

        /**
         * GETTER     
         */

        public String getId(){
            return num_portable;
        }
        public String getNum_portable() {
            return num_portable;
        }

        public Boolean getsexe(){
            return sexe;
        }

        public int getdate_naissance(){
            return date_naissance;
        }     


        /**
         * SETTER     
         */


        public void setsexe(Boolean sexe){
            this.sexe=sexe;
        }

        public void setdate_naissance(int date_naissance){
            this.date_naissance=date_naissance;
        }      

}

Your class to do CRUD operations:

你的班级做CRUD操作:

public class UserCRUD {

    private static UserCRUD user_crud = null;
    private static final Logger log = Logger.getLogger(UserCRUD.class.getName());

    static {
          ObjectifyService.register(User.class);
    }

    private UserCRUD (){

    }

    public static synchronized UserCRUD getInstance() {
          if (null == user_crud) {
           user_crud = new UserCRUD();
          }
      return user_crud;
    }


    public User findUser(String NumeroPhone) {
          User user = ofy().load().type(User.class).id(NumeroPhone).now();      
          return user;
    }
}

Your endpoint class, which called by your endpoint (when you generated endpoint API):

您的端点类,由您的端点调用(生成端点API时):

@Api(

    name = "userendpoint",
    version = "v1"
 )
public class UserEndPoint { 

     @ApiMethod(name = "FindUser", httpMethod = ApiMethod.HttpMethod.GET)
     public User getUser(@Named("numero_portable") String NumPortable){
         return UserCRUD.getInstance().findUser(NumPortable);
     }
}

Hope that will help you,

希望能帮到你,

#1


2  

Same problem than you when I started to learn objectify and endpoints.

当我开始学习客体化和端点时,与你相同的问题。

Here is a tuto from website (Sorry that's in french): http://blog.xebia.fr/2014/06/23/google-app-engine-cloud-endpoint-creer-notre-api-v2-et-lutiliser-avec-angularjs/

这是来自网站的tuto(抱歉,这是法语):http://blog.xebia.fr/2014/06/23/google-app-engine-cloud-endpoint-creer-notre-api-v2-et-lutiliser -avec-angularjs /

EDIT: You can find in english, this amazing website which explain in details my code below : http://rominirani.com/2014/08/26/gradle-tutorial-part-9-cloud-endpoints-persistence-android-studio/

编辑:你可以找到英文,这个惊人的网站,详细解释我的代码如下:http://rominirani.com/2014/08/26/gradle-tutorial-part-9-cloud-endpoints-persistence-android-studio /

In simple, you have to have three classes:

简单来说,你必须有三个类:

Your object :

你的对象:

@Entity
@Index

public class User {


        @Id private String num_portable; 
        private Boolean sexe;
        private int date_naissance;

        //Constructeur par défaut (Obligatoire pour Objectify)
        public User(){}

        public User (String num_portable, Boolean sexe, int date_naissance){

            this.num_portable=num_portable; //Numéro de portable user
            this.sexe=sexe; 
            this.date_naissance=date_naissance; 

        }

        /**
         * GETTER     
         */

        public String getId(){
            return num_portable;
        }
        public String getNum_portable() {
            return num_portable;
        }

        public Boolean getsexe(){
            return sexe;
        }

        public int getdate_naissance(){
            return date_naissance;
        }     


        /**
         * SETTER     
         */


        public void setsexe(Boolean sexe){
            this.sexe=sexe;
        }

        public void setdate_naissance(int date_naissance){
            this.date_naissance=date_naissance;
        }      

}

Your class to do CRUD operations:

你的班级做CRUD操作:

public class UserCRUD {

    private static UserCRUD user_crud = null;
    private static final Logger log = Logger.getLogger(UserCRUD.class.getName());

    static {
          ObjectifyService.register(User.class);
    }

    private UserCRUD (){

    }

    public static synchronized UserCRUD getInstance() {
          if (null == user_crud) {
           user_crud = new UserCRUD();
          }
      return user_crud;
    }


    public User findUser(String NumeroPhone) {
          User user = ofy().load().type(User.class).id(NumeroPhone).now();      
          return user;
    }
}

Your endpoint class, which called by your endpoint (when you generated endpoint API):

您的端点类,由您的端点调用(生成端点API时):

@Api(

    name = "userendpoint",
    version = "v1"
 )
public class UserEndPoint { 

     @ApiMethod(name = "FindUser", httpMethod = ApiMethod.HttpMethod.GET)
     public User getUser(@Named("numero_portable") String NumPortable){
         return UserCRUD.getInstance().findUser(NumPortable);
     }
}

Hope that will help you,

希望能帮到你,