在检查手机号码是否存在后,我试图将数据存储在 Google App Engine Datastore 中,但即使手机号码在数据库中,代码也始终显示“失败”。它显示失败,但仍将数据存储在 Datastore 中。
请检查这里的代码,让我知道我的错误是什么:
String name= request.getParameter("name");
String email=request.getParameter("email");
String mobileno= request.getParameter("mobileno");
String password= request.getParameter("passwd");
String status="";
//
Query query = new Query("dailyquizuser");
query.addFilter("mobileno", Query.FilterOperator.EQUAL, mobileno);
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
PreparedQuery pq = datastore.prepare(query);
Entity dailyquizuserentity = pq.asSingleEntity();
out.println("dailyquizuserentity: " + dailyquizuserentity);
if(dailyquizuserentity != null){
status="failure";
out.println(status);
} else {
Key dailyquizuserKey = KeyFactory.createKey("dailyquizuser", "dailyquiz");
Entity dailyquizuser = new Entity("dailyquizuser", dailyquizuserKey);
dailyquizuser.setProperty("name", name);
dailyquizuser.setProperty("email", email);
dailyquizuser.setProperty("mobileno", mobileno);
dailyquizuser.setProperty("password", password);
DatastoreService datastore1 = DatastoreServiceFactory.getDatastoreService();
datastore1.put(dailyquizuser);
out.println("dailyquizuser: " + dailyquizuser);
status="success";
out.println(status);
}
%>