标签:text ide rri admin dmi ons null 实现类 arm
一:查询
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("得id值为"+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("数据"+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; //流
try {
out = ServletActionContext.getResponse().getWriter();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
response.setHeader("Cache-Control", "no-cache"); //取消浏览器缓存
System.out.println("这是?"+json);
out.print(json);
out.flush();
out.close();//关闭流
}
2.接口
public List<?> mtadopt(String hql, Object[] values);
3接口实现类
@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;
}
标签:text ide rri admin dmi ons null 实现类 arm
原文地址:http://www.cnblogs.com/huangchaof/p/shenZhen_2311685383.html