One: Query
1.action
public void mtadopt () {
HttpSession session = Servletactioncontext.getrequest (). GetSession ();
HttpServletResponse response = Servletactioncontext.getresponse ();
HttpServletRequest request = Servletactioncontext.getrequest ();
String id=request.getparameter ("id");
SYSTEM.OUT.PRINTLN ("The ID value is" +id);
String[] Values=new String[]{id};
SYSTEM.OUT.PRINTLN (1);
String hql= "Select S from Smrz s where s.idcard=?";
SYSTEM.OUT.PRINTLN (2);
List<smrz> mtadopt= (list<smrz>) sharedfarmadminmanager.mtadopt (hql,values);
SYSTEM.OUT.PRINTLN (3);
SYSTEM.OUT.PRINTLN ("Data" +mtadopt.size ());
SYSTEM.OUT.PRINTLN (4);
Gson Gson = new Gson ();
SYSTEM.OUT.PRINTLN (5);
String json = Gson.tojson (mtadopt.get (0));
SYSTEM.OUT.PRINTLN (6);
PrintWriter out = null;//stream
try {
out = Servletactioncontext.getresponse (). Getwriter ();
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
Response.setheader ("Cache-control", "No-cache"); Canceling the browser cache
System.out.println ("This is?" "+json);
Out.print (JSON);
Out.flush ();
Out.close ();//Close stream
}
2. Interface
Public list<?> mtadopt (String hql, object[] values);
3 Interface Implementation Class
@Override
Public list<?> mtadopt (String hql, object[] values) {
List list= null;
Query query = this.getsession (). CreateQuery (HQL);
if (query! = NULL && values! = null && values.length > 0) {
for (int i = 0; i<values.length; i++) {
Query.setparameter (i, values[i]);
}
}
List = Query.list ();
return list;
}
SSH and mobile to implement additions and deletions to check the interface