JAVA报表系统流程

1.前台页面函数(前台页面先定义参数、执行前台页面的函数并传送送参数到后台ACTION)例如:

    售出时间自: id="starttime" name="starttime"  style="width: 200px;" editable="false" value="${starttime }"/>         至:id="endtime" name="endtime"  style="width: 200px;" editable="false" value="${currentDate }" />         查询

2.ACTION里定义变量用来接收前台传送的参数,定义类的列表用来接受后台(sevice/dao/imp)执行后传回的数据

private String starttime;
private String endtime;
public String getStarttime() {
return starttime;
}
public void setStarttime(String starttime) {
this.starttime = starttime;
}
public String getEndtime() {
return endtime;
}
public void setEndtime(String endtime) {
this.endtime = endtime;
}

private List huipiaozhoubaos;
public List getHuipiaozhoubaos() {
return huipiaozhoubaos;
}
public void setHuipiaozhoubaos(List huipiaozhoubaos) {
this.huipiaozhoubaos = huipiaozhoubaos;
}

public String zhoubao(){
if(starttime==null || endtime==null){
huipiaozhoubaos = new ArrayList();
}else{
huipiaozhoubaos = service.totalZhoubaoData(starttime, endtime);
}
return "shouchutongji";
}

3.SERVICE和DAOCUSTOM中分别定义用来执行的函数

public List totalZhoubaoData(String starttime, String endtime){
return dao.totalZhoubaoData(starttime, endtime);}

public interface HuipiaoDaoCustom {

List totalZhoubaoData(String starttime, String endtime);}

4.DAOIMPL中具体写sql语句及要执行的代码

@Override
public List totalZhoubaoData(String starttime, String endtime) {
try {
String queryStr = "SELECT o from Huipiao o where "
+ " (o.status>=:rukustatus and o.status<:chukustatus) "
+ " or (o.status=:chukustatus and  o.shouchushijian between :starttime and :endtime) "
+ " order by o.status ";
Query query = em.createQuery(queryStr);
query.setParameter("rukustatus",
IntValueDef.HUIPIAO_STATUS_INVENTORY);
query.setParameter("chukustatus", IntValueDef.HUIPIAO_STATUS_OUT);
query.setParameter("starttime", starttime);
query.setParameter("endtime", endtime);
@SuppressWarnings("unchecked")
List result = query.getResultList();
return result;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

需要注意的是以上例子是建立在有一个类(这里是Huipiao类)完全包含所需要提取的数据,即能从一个表中提取所有的数据才可以这样使用(sql语句用的是标准sql语言即对象的概念),如果所需数据不能仅从一个类中的数据提取即需要几个表联合查询就需要多一个步骤,即新建一个类并在这个类中定义变量包含所有所需的数据并以这些数据建立构造函数,在第4步中需要在List result = query.getResultList();后多加两句代码:

List<自定义的类名> objs = castEntity(result, 自定义的类名.class); 

return objs;

其中castEntity的作用是将查询结果赋值到自定义的类里面,例如

private static List castEntity(List list, Class clazz)
throws Exception {
List returnList = new ArrayList();
for (Object[] o : list) {
Constructor c0 = clazz.getDeclaredConstructor(new Class[] {
String.class, String.class, String.class, BigDecimal.class,
BigDecimal.class, BigDecimal.class, BigDecimal.class,
BigDecimal.class
});
c0.setAccessible(true);
returnList.add(c0.newInstance(o));
}
return returnList;
}

红字为参数即变量的类型,要与自定义类里面的构造函数的变量一一对应

5.最后在前台中用c:foreach循环得到的那个列表里所需的数据





${mingxi.piaohao}
${mingxi.fukuanhang }
${mingxi.chupiaojine}
${mingxi.fromuser}
${mingxi.fromassistants}
${mingxi.fromkehu.gongsimingcheng}
${mingxi.gourujine}
${mingxi.gourushijian}

 

${mingxi.wangdianquyu}


${mingxi.piaohao}
${mingxi.fukuanhang }
${mingxi.chupiaojine}
${mingxi.fromuser}
${mingxi.fromassistants}
${mingxi.fromkehu.gongsimingcheng}
${mingxi.gourujine}
${mingxi.gourushijian}
${mingxi.touser}
${mingxi.toassistants}
${mingxi.tokehu.gongsimingcheng}
${mingxi.shouchujine}
${mingxi.shouchushijian}
${mingxi.maoli}
${mingxi.wangdianquyu}




你可能感兴趣的:(JAVA报表系统流程)