我在数据库(Mysql)的帮助下在netbeans中创建了restful webservices, 从数据库创建实体,然后从实体创建restful webservice,使用存储过程,我从webservice获得响应。
退回outpout:
{"attendee":[[13885,4,"Mar 28, 2018 5:36:45 PM",null,null,"Active but not Vefied","5f4db43b5ad965aa1dfd27a2c8feb1e7","9828409828","Sanjay",null,"Sanjay Sharma",null,"Mr"null,"Attendee","sanjay",null,"Mar 28, 2018","Sharma",null,"RegularUser",13882,"password",null]],"success":true}
必填项:
{"attendee":[["**key**":"13885","**above key is missing**":"4","Mar 28, 2018 5:36:45 PM",null,null,"Active but not Vefied","5f4db43b5ad965aa1dfd27a2c8feb1e7","9828409828","Sanjay",null,"Sanjay Sharma",null,"Mr"null,"Attendee","sanjay",null,"Mar 28, 2018","Sharma",null,"RegularUser",13882,"password",null]],"success":true}
json的响应键中的 为空
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
JsonObject jo = new JsonObject();
List<Attendee> resultList = new ArrayList<>();
em = this.getEntityManager();
resultList = em.createNamedStoredProcedureQuery("LOGIN_VALID").setParameter("USER", userName).setParameter("PASS", password).getResultList();
JsonElement je = gson.toJsonTree(resultList, new TypeToken<List<Attendee>>() {
}.getType());
com.google.gson.JsonArray jsonArray = gson.toJsonTree(resultList).getAsJsonArray();
System.out.println(" " + jsonArray);
JsonArray jsonA = je.getAsJsonArray();
// System.out.println(" jsonAt=rray "+jsonA);
if (resultList != null) {
jo.add("attendee", je);
jo.addProperty("success", Boolean.TRUE);
} else {
jo.addProperty("success", Boolean.FALSE);
}
return Response.ok(jo.toString()).build();