老师给出的要求是多条件查询,因此就要添加查询条件,因此我就是将查询条件也封装成了一个Bean类,然后对查询论文的方法进行修改,以此来实现多条件查询。
代码如下:
public void findlunwen(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
request.setCharacterEncoding("utf-8");
int tonum=Integer.parseInt(request.getParameter("sum"));
int realnum=Integer.parseInt(request.getParameter("realsum"));
List<demBean> findlist=new ArrayList<>();
demBean dbean=null;
dbean=new demBean("AND",request.getParameter("tiaojian"),request.getParameter("firinput"),request.getParameter("jingzhun"));
findlist.add(dbean);
for(int i=1;i<tonum;i++) {
if(request.getParameter("input"+i)!=""&&request.getParameter("input"+i)!=null) {
dbean=new demBean(request.getParameter("lianjie"+i),request.getParameter("tiaojian"+i),request.getParameter("input"+i),request.getParameter("jingdu"+i));
findlist.add(dbean);
}
}
System.out.println(realnum+"总数为"+findlist.size());
for(int i=0;i<findlist.size();i++) {
System.out.println(findlist.get(i).toString());
}
PrintWriter out = response.getWriter();
//String name = request.getParameter("name").trim();
List<lunwenBean> list = dao.getselectlunwen(findlist);
JSONArray json=new JSONArray();
for(int i=0;i<list.size();i++) {
JSONObject ob=new JSONObject();
ob.put("title", list.get(i).getTitle());
ob.put("zuozhe", list.get(i).getZuozhe());
ob.put("zhaiyao", list.get(i).getZhaiyao());
ob.put("time", list.get(i).getTime());
ob.put("lianjie", list.get(i).getLianjie());
json.add(ob);
}
//System.out.println("JSON"+json.toString());
System.out.println("zongshu"+list.size());
out.write(json.toString());
}