grid.load({
type1:type1,
timestmp:timestamp
});
}
按照上面我们就可以在后台的listAll中对接收到的数据进行判断,然后显示对应的数据
这个地方有一个特点时间的传递并不是按照yyyy-MM-dd这种格式,而是利用时间戳传递到后台,也就是说传递的是一个long类型是数据,我们来看一看后台是怎样进行接收的
public void listAll(HttpServletRequest request, HttpServletResponse response) throws Exception{
String type=request.getParameter("type1");
String lstr=request.getParameter("timestmp");
long time=0;
if(lstr!=null && isNumeric(lstr)){
time=Long.parseLong(lstr);
}
Date date1=new Date();
date1.setTime(time);
Date date2=new Date();
date2.setTime(time+24*60*60*1000);
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
String sql="select * from bookinfo";
if(type!= null && type.length()>0 && time==0)
{
sql="select * from bookinfo where booktype="+Integer.parseInt(type);
}
else if(time!=0 && type.length()==0)
{
sql ="select * from bookinfo where buydate between ""+ sdf.format(date1) +"" and ""+sdf.format(date2)+""";
}
else if(time!=0 && type.length()>0)
{
sql ="select * from bookinfo where booktype="+Integer.parseInt(type)+" and buydate between ""+ sdf.format(date1) +"" and ""+sdf.format(date2)+""";
}
else
{
sql ="select * from bookinfo";
}
System.out.println(sql);
//要知道的是联合查询中需要得到的List也是显示出来的
List list=mdao.getList(sql);
//实现的是分页
int pageSize=Integer.parseInt(request.getParameter("pageSize"));
int pageIndex=Integer.parseInt(request.getParameter("pageIndex"));
List sub_list=new ArrayList<>();
int start=pageIndex*pageSize;
for(int i=start;i<list.size() && i<start+pageSize;i++)
{
sub_list.add(list.get(i));
}
String json=JsonUtil.listToJson(sub_list, "yyyy-MM-dd hh:mm:ss");
System.out.println(json);
json=JsonData.modifyJson(json);
json=json.replaceFirst("null", list.size()+"");
response.getWriter().write(json); }
然后在后台将时间戳转换成为一定的格式,我们就可以在数据库中户进行搜索了,还有的是sql语句中时间两边是要加上双引号的。
总之,我们利用JQuerymini-ui在进行数据时间数据传递的时候,如果仅仅传递一个时间,那么时间的格式并不是我们想要的那么满意,而且在后台我们要进行各种各样的判断,现在我们传递时间戳会减少一些判断,并且时间的格式也可以很容易的进行转换。










