忙了2天的查询数据库结果在JSP中展示

来源:互联网 发布:内网怎么访问阿里云 编辑:程序博客网 时间:2024/06/06 08:24

Action

package com.shbc.vem.action;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.shbc.vem.dao.IVendorDAO;
import com.shbc.vem.dao.hibernate.VendorDAOImpl;
import com.shbc.vem.pojo.Vendor;


public class VendorBaseAction extends ActionSupport {


private Date startTime;
private Date stopTime;
private HttpServletRequest request;

public ArrayList<Vendor> vendorList;

IVendorDAO vendordao = new VendorDAOImpl();

Vendor vendor = new Vendor();

@Override
public String execute() throws Exception {

System.out.println(startTime);
System.out.println(stopTime);

vendor.setStartTime(startTime);
vendor.setStopTime(stopTime);

vendorList =   vendordao.getVendor(startTime, stopTime, vendor);


for(Vendor v : vendorList) {
System.out.println(v.getName());
}



return SUCCESS;
}


public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public Date getStopTime() {
return stopTime;
}
public void setStopTime(Date stopTime) {
this.stopTime = stopTime;
}

public HttpServletRequest getRequest() {
return request;
}

public void setRequest(HttpServletRequest request) {
this.request = request;
}

public ArrayList<Vendor> getVendorList() {
return vendorList;
}

public void setVendorList(ArrayList<Vendor> vendorList) {
this.vendorList = vendorList;
}


}


DAO

package com.shbc.vem.dao.hibernate;


import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;


import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.dao.DataAccessException;


import com.dbw.core.dao.hibernate.DAOImpl;
import com.dbw.core.dao.page.PaginationSupport;
import com.shbc.vem.dao.IVendorDAO;
import com.shbc.vem.dto.VendorDto;
import com.shbc.vem.pojo.Vendor;
import com.shbc.vem.service.HibernateUtils;
/**
 * 
 * @author Administrator
 *
 */
public class VendorDAOImpl extends DAOImpl implements IVendorDAO {

private static final Log log = LogFactory.getLog(VendorDAOImpl.class);



//获列表分页
@SuppressWarnings("unchecked")
public PaginationSupport getVendors(int pageSize, int startIndex, Map<String, Object> condition) throws DataAccessException{
int totalCount = 0;
List list = null;
List result = new ArrayList();
String hql = "select v.*,o.NAME as orgName,t.NAME as typeName,p.NAME as parentName,s.CODEITEM_DESC from vendor v left join SY_ORGANIZATION o on v.ORG_ID=o.ORG_ID left join VENDOR_TYPE t on t.TYPE_ID = v.TYPE_ID left join VENDOR_TYPE p on p.TYPE_ID = t.PARENT_ID left join SY_CODEITEM s on s.CODESET_ID='03' and s.CODEITEM_ID=v.KIND";
String where = " where 1=1";
Session session = this.getSession();
Query q = session.createSQLQuery(hql.concat(where)).addEntity(Vendor.class)
.addScalar("orgName", Hibernate.STRING)
.addScalar("typeName", Hibernate.STRING)
.addScalar("parentName", Hibernate.STRING)
.addScalar("CODEITEM_DESC", Hibernate.STRING);
q.setFirstResult(startIndex);
q.setMaxResults(pageSize);

list = q.list();
for(int i=0; i<list.size(); i++){
VendorDto dto = new VendorDto();
Object[] objs = (Object[])list.get(i);
try {
PropertyUtils.copyProperties(dto, objs[0]);
} catch (Exception e) {
e.printStackTrace();
}
dto.setContact((String)objs[1]);
dto.setAsssetSize((String)objs[2]);
dto.setBusinessScope((String)objs[3]);
dto.setCancelMemo((String)objs[4]);
result.add(dto);
}
hql = "select count(*) from Vendor o";
q = session.createQuery(hql.concat(where));
totalCount = Integer.parseInt(q.uniqueResult().toString());
return new PaginationSupport(result, totalCount, pageSize, startIndex);
}

public Integer addVendor(Vendor o) throws DataAccessException{
return (Integer)super.save(o);
}

public Vendor getVendor(Integer id) throws DataAccessException{
return (Vendor)get(Vendor.class, id);
}

public void updateVendor(Vendor o) throws DataAccessException{
super.update(o);
}

public void deleteVendor(Integer id) throws DataAccessException{
String hql = "delete from Vendor where vendorId=:id";
Session session = this.getSession();
Query q = session.createQuery(hql);
q.setParameter("id", id);
q.executeUpdate();
}


@Override
public ArrayList getVendor(Date startTime, Date stopTime, Vendor entity)
throws DataAccessException {
HibernateUtils hibernateUtils = new HibernateUtils();
Session session = hibernateUtils.getSession();


ArrayList<Vendor> vendors= (ArrayList<Vendor>) session.createQuery("from Vendor v where v.addTime between ? and ?")   
        .setParameter(0, startTime)   
        .setParameter(1, stopTime)   
        .list();   

System.out.println(vendors.getClass().getName());

for(int i=0; i<vendors.size(); i++){




}
return vendors;
}


}





JSP

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>

<%@include file="../common/comtop.jsp"%>
<%@taglib uri='/WEB-INF/tld/app.tld' prefix='app'%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<%@page import="com.shbc.vem.dao.hibernate.VendorDAOImpl;"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>基本情况报表</title>
<script type="text/javascript" src="<%=ctxPath%>/js/common/Tooltip.js"></script>
<script type="text/javascript" src="<%=ctxPath%>/js/common/dbwtool.js"></script>
<script type="text/javascript" src="<%=ctxPath%>/js/common/jquery.form.js"></script>
<script type="text/javascript" src="<%=ctxPath%>/js/common/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
function doDelete(id){
if(!confirm('确定删除所选记录?')) return false;
var form = $("form[name=mainForm]");
var options  = {
           url:'<%=ctxPath%>/work/deleteDeviceRun.action?id='+id,
           type:'post',
           success:function(data){
                     if(data.indexOf("失败") != -1) {
                     alert(data);
                     }else{
                     jQuery('#mainForm').submit();
                     }
           }
      };
  form.ajaxSubmit(options);
}
function doAudit(id){
if(!confirm('确定审核所选记录?')) return false;
var form = $("form[name=mainForm]");
var options  = {
           url:'<%=ctxPath%>/work/auditDeviceRun.action?id='+id,
           type:'post',
           success:function(data){
                     if(data.indexOf("失败") != -1) {
                     alert(data);
                     }else{
                     jQuery('#mainForm').submit();
                     }
           }
      };
  form.ajaxSubmit(options);
}
function doSearch(){
$('#mainForm').submit();
}
$(document).ready(function () {
styleTable2();
});
    </script>
</head>
<body>


<div class="titleBar"><span style="float: left;">基本情况报表</span><br/>
  <span style="float: right"><a href="#"><img src='<%=ctxPath%>/image/admin/xls.gif' />导出为EXCEL</a></span>


</div>
<s:form id="mainForm" name="mainForm" action="VendorBaseAction.do"
namespace="/vendor" method="post">
<table class="search" >
<tr>
<td>
开始时间:
<input id="startTime" name="startTime" value="<fmt:formatDate value="${startTime}" pattern="yyyy-MM-dd"/>" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/>
结束时间: 
<input id="stopTime" name="stopTime" value="<fmt:formatDate value="${stopTime}" pattern="yyyy-MM-dd"/>" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/>
<a href="#" onclick="doSearch();"><img src="<%=ctxPath%>/image/admin/btn_search.gif">查询</a></td>
</tr>
</table>
<table class="panelpos">
<tbody id="main">
<tr>
<td colspan="18" align="center"> <h1>交通银行上海市分行供应商基本情况报表</h1></td>
</tr>
<tr>
<td  width="150" align="center"><b>类别</b></td>
<td width="150" align="center"><b>项目</b></td>
<td width="150" align="center"><b>归口管理部门</b></td>
<td width="150" align="center"><b>企业名称</b></td>
<td width="150" align="center"><b>企业性质</b></td>
<td width="150" align="center"><b>注册资金(万元)</b></td>
<td width="150" align="center"><b>资产规模</b></td>
<td width="150" align="center"><b>主营业务</b></td>
<td width="150" align="center"><b>经营范围</b></td>
<td width="150" align="center"><b>资质证书</b></td>
<td width="150" align="center"><b>正式员工数</b></td>
<td width="150" align="center"><b>主要客户</b></td>
<td width="150" align="center"><b>注册地址</b></td>
<td width="150" align="center"><b>办公地址</b></td>
<td width="150" align="center"><b>办公地产权</b></td>
<td width="150" align="center"><b>联系人</b></td>
<td width="150" align="center"><b>联系方式</b></td>
<td width="150" align="center"><b>是否现场考察</b></td>
</tr>
 
<c:forEach items="${vendorList}" var="o" varStatus="status">
<tr>


<td>${o.typeId}</td><!-- 类别 -->
<td>${o.code}</td>
<td>${o.orgId}</td><!--  -->
<td>${o.name}</td>
<td>${o.kind}</td>

<td>${o.registerCapital}</td>
<td>${o.asssetSize}</td>
<td>${o.mainBusiness}</td>
<td>${o.businessScope}</td>
<td>${o.certificate}</td>
<td>${o.employeeNumber}</td>
<td>${o.mainCustomer}</td>
<td>${o.registerAddress}</td>
<td>${o.workAddress}</td>
<td>${o.officeRights}</td>
<td>${o.contact}</td>
<td>${o.contactChannel}</td>
<td>${o.isSiteVisit}</td> 



</tr>
</c:forEach>
<c:if test="${page.recordCount==0}">
<tr>
<td bgcolor="#CCCCFE" align="center" colspan="8">未找到相关数据</td>
</tr>
</c:if>
</tbody>
</table>
<app:page pageNo="${pageNo}" recordCount="${page.recordCount}"
pageSize="${pageSize}" url="${ctxPath}work/deviceRun.do"
formName="mainForm" />
</s:form>
</body>
</html>