JAVA报表系统流程

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

<html>

<head>

<script>
function searchbypara() {
var starttime = $('#starttime').datebox('getValue');
var endtime = $('#endtime').datebox('getValue');
location.href = 'huipiao!zhoubao.action?starttime=' + starttime+ '&endtime=' + endtime;
}

</script>

</head>

<body>

<div id="searchTime">

    售出时间自:<input class="easyui-datebox" id="starttime" name="starttime"  style="width: 200px;" editable="false" value="${starttime }"/>&nbsp;&nbsp;&nbsp;&nbsp;     至:<input class="easyui-datebox" id="endtime" name="endtime"  style="width: 200px;" editable="false" value="${currentDate }" />&nbsp;&nbsp;&nbsp;&nbsp;     <a id="searchbtn" href="javascript:void(0)" class="easyui-linkbutton"  data-options="plain:true,iconCls:'icon-search'"  οnclick='searchbypara()'>查询</a> </div>

</body>

</html>

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<Huipiao> huipiaozhoubaos;
public List<Huipiao> getHuipiaozhoubaos() {
return huipiaozhoubaos;
}
public void setHuipiaozhoubaos(List<Huipiao> huipiaozhoubaos) {
this.huipiaozhoubaos = huipiaozhoubaos;
}

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

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

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

public interface HuipiaoDaoCustom {

List<Huipiao> totalZhoubaoData(String starttime, String endtime);}

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

@Override
public List<Huipiao> 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<Huipiao> result = query.getResultList();
return result;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

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

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

return objs;

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

private static <T> List<T> castEntity(List<Object[]> list, Class<T> clazz)
throws Exception {
List<T> returnList = new ArrayList<T>();
for (Object[] o : list) {
Constructor<T> 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循环得到的那个列表里所需的数据

<c:forEach items="${huipiaozhoubaos}" var="mingxi" varStatus="status">
<tr>
<c:choose>
<c:when test="${mingxi.status>=5&&mingxi.status<19}">
<td bgcolor="green" align="center">${mingxi.piaohao}</td>
<td bgcolor="green" align="center">${mingxi.fukuanhang }</td>
<td bgcolor="green" align="center">${mingxi.chupiaojine}</td>
<td bgcolor="green" align="center">${mingxi.fromuser}</td>
<td bgcolor="green" align="center">${mingxi.fromassistants}</td>
<td bgcolor="green" align="center">${mingxi.fromkehu.gongsimingcheng}</td>
<td bgcolor="green" align="center">${mingxi.gourujine}</td>
<td bgcolor="green" align="center">${mingxi.gourushijian}</td>
<c:forEach var="x" begin="1" end="6">
<td bgcolor="green" align="center">&nbsp;</td>
</c:forEach>
<td bgcolor="green" align="center">${mingxi.wangdianquyu}</td>
</c:when>
<c:otherwise>
<td align="center">${mingxi.piaohao}</td>
<td align="center">${mingxi.fukuanhang }</td>
<td align="center">${mingxi.chupiaojine}</td>
<td align="center">${mingxi.fromuser}</td>
<td align="center">${mingxi.fromassistants}</td>
<td align="center">${mingxi.fromkehu.gongsimingcheng}</td>
<td align="center">${mingxi.gourujine}</td>
<td align="center">${mingxi.gourushijian}</td>
<td align="center">${mingxi.touser}</td>
<td align="center">${mingxi.toassistants}</td>
<td align="center">${mingxi.tokehu.gongsimingcheng}</td>
<td align="center">${mingxi.shouchujine}</td>
<td align="center">${mingxi.shouchushijian}</td>
<td align="center">${mingxi.maoli}</td>
<td align="center">${mingxi.wangdianquyu}</td>
</c:otherwise>
</c:choose>
</tr>
</c:forEach>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值