<%@ page language="java" pageEncoding="UTF-8"%> <%@ include file="../../base.jsp"%> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>打印出货表</title> <script language="javascript" src="${ctx}/js/datepicker/WdatePicker.js"></script> </head> <body> <form method="post"> <div id="menubar"> <div id="middleMenubar"> <div id="innerMenubar"> <div id="navMenubar"> <ul> <li id="save"><a href="#" onclick="formSubmit('print.action','_self');">打印</a></li> </ul> </div> </div> </div> </div> <div class="textbox" id="centerTextbox"> <div class="textbox-header"> <div class="textbox-inner-header"> <div class="textbox-title"> 出货表月统计 </div> </div> </div> <div> <div> <table class="commonTable" cellspacing="1"> <tr> <td class="columnTitle_mustbe">船期:</td> <td class="tableContent"> <input type="text" style="width: 90px" name="inputDate" readonly class="Wdate" onclick="WdatePicker({el:this,isShowOthers:true,dateFmt:'yyyy-MM'});"/> </td> </tr> </table> </div> </div> </form> </body> </html>
package cn.hpu.jk.controller.cargo.outproduct; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import cn.hpu.jk.controller.BaseController; @Controller public class OutProductController extends BaseController{ //转向输入年月的页面 @RequestMapping("/cargo/outproduct/toedit.action") public String toedit(){ return "/cargo/outproduct/jOutProduct.jsp"; } //打印 @RequestMapping("/cargo/outproduct/print.action") public void print(String inputDate){ //inputDate格式:yyyy-MM System.out.println(inputDate); } }
</div> <div class="panel"> <div class="panel_icon"><img src="${ctx}/skin/default/images/icon/document_into.png"/></div> <div class="panel-header"> <div class="panel-title">货运管理</div> <div class="panel-content"> <ul> <li><a href="${ctx }/cargo/contract/list.action" onclick="linkHighlighted(this)" target="main" id="aa_1">购销合同</a></li> <li><a href="${ctx }/cargo/outproduct/toedit.action" onclick="linkHighlighted(this)" target="main" id="aa_1">出货表</a></li> </ul> </div> </div> </div>
效果:
select c.custom_name,c.contract_no,cp.product_no,cp.cnumber,cp.factory_name,cp.exts,c.delivery_period,c.ship_time,c.trade_terms from ( select contract_id,custom_name,contract_no,delivery_period,ship_time,trade_terms from contract_c ) c left join ( select contract_id,product_no,cnumber||packing_unit as cnumber,factory_name,exts from contract_product_c ) cp on c.contract_id=cp.contract_id where to_char(c.ship_time,'yyyy-MM')= '2014-11'
package cn.hpu.jk.vo; public class OutProductVO { private String customName; private String contract_no; private String productNo; private String cnumber; private String factoryName; private String exts; private String delivery_preriod; private String ship_time; private String tradeTerms; //get和set方法省略 }
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="cn.hpu.jk.mapper.OutProductMapper"> <resultMap type="cn.hpu.jk.vo.OutProductVO" id="OutProductRM"> <result property="customName" column="CUSTOM_NAME" jdbcType="VARCHAR"/> <result property="contractNo" column="CONTRACT_NO" jdbcType="VARCHAR"/> <result property="productNo" column="PRODUCT_NO" jdbcType="VARCHAR"/> <result property="cnumber" column="CNUMBER" jdbcType="VARCHAR"/> <result property="factoryName" column="FACTORY_NAME" jdbcType="VARCHAR"/> <result property="exts" column="EXTS" jdbcType="VARCHAR"/> <result property="delivery_preriod" column="DELIVERY_PRERIOD" jdbcType="VARCHAR"/> <result property="ship_time" column="SHIP_TIME" jdbcType="VARCHAR"/> <result property="tradeTerms" column="TRADE_TERMS" jdbcType="VARCHAR"/> </resultMap> <select id="find" parameterType="string" resultMap="OutProductRM"> select c.custom_name,c.contract_no,cp.product_no,cp.cnumber,cp.factory_name,cp.exts, to_char(c.delivery_period,'yyyy-mm-dd')as delivery_period, to_char(c.ship_time,'yyyy-mm-dd')as ship_time,c.trade_terms from ( select contract_id,custom_name,contract_no,delivery_period,ship_time,trade_terms from contract_c ) c left join ( select contract_id,product_no,cnumber||packing_unit as cnumber,factory_name,exts from contract_product_c ) cp on c.contract_id=cp.contract_id where to_char(c.ship_time,'yyyy-MM')= #{inputDate} </select> </mapper>
package cn.hpu.jk.dao; import cn.hpu.jk.vo.OutProductVO; public interface OutProductDao extends BaseDao<OutProductVO>{ }
package cn.hpu.jk.dao.impl; import org.springframework.stereotype.Repository; import cn.hpu.jk.dao.OutProductDao; import cn.hpu.jk.vo.OutProductVO; @Repository //为了包扫描的时候这个Dao被扫描到 public class OutProductDaoImpl extends BaseDaoImpl<OutProductVO> implements OutProductDao{ public OutProductDaoImpl(){ //设置命名空间 super.setNs("cn.hpu.jk.mapper.OutProductMapper"); } }
package cn.hpu.jk.service; import java.util.List; import cn.hpu.jk.vo.OutProductVO; public interface OutProductService { public List<OutProductVO> find(String inputDate); }
package cn.hpu.jk.service.impl; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import cn.hpu.jk.dao.OutProductDao; import cn.hpu.jk.service.OutProductService; import cn.hpu.jk.vo.OutProductVO; public class OutProductServiceImpl implements OutProductService{ @Resource OutProductDao outProductDao; @Override public List<OutProductVO> find(String inputDate) { Map paraMap=new HashMap(); paraMap.put("inputDate", inputDate); return outProductDao.find(paraMap); } }
<bean name="outProductService" class="cn.hpu.jk.service.impl.OutProductServiceImpl"/>
package cn.hpu.jk.controller.cargo.outproduct; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import cn.hpu.jk.controller.BaseController; import cn.hpu.jk.service.OutProductService; import cn.hpu.jk.vo.OutProductVO; @Controller public class OutProductController extends BaseController{ @Resource OutProductService outProductService; //转向输入年月的页面 @RequestMapping("/cargo/outproduct/toedit.action") public String toedit(){ return "/cargo/outproduct/jOutProduct.jsp"; } //打印 @RequestMapping("/cargo/outproduct/print.action") public void print(String inputDate){ //inputDate格式:yyyy-MM List<OutProductVO> dataList=outProductService.find(inputDate); System.out.println(dataList.size()); System.out.println(inputDate); } }
//打印 @RequestMapping("/cargo/outproduct/print.action") public void print(String inputDate) throws IOException{ //inputDate格式:yyyy-MM List<OutProductVO> dataList=outProductService.find(inputDate); /*System.out.println(dataList.size()); System.out.println(inputDate);*/ Workbook wb=new HSSFWorkbook(); Sheet sheet=wb.createSheet(); Row nRow=null; Cell nCell=null; int rowNo=0; //行号 int cellNo=1;//列号 rowNo++; //配置标题行 String [] title=new String[]{"客户","订单号","货号","数量","工厂","附件","工厂交期","船期","贸易条款"}; nRow=sheet.createRow(rowNo++); for (int i = 0; i < title.length; i++) { nCell=nRow.createCell(i+1); nCell.setCellValue(title[i]); } //处理数据 for (int i = 0; i < dataList.size(); i++) { OutProductVO op=dataList.get(i); nRow=sheet.createRow(rowNo++); cellNo=1;//列号初始化 nCell=nRow.createCell(cellNo++); nCell.setCellValue(op.getCustomName()); nCell=nRow.createCell(cellNo++); nCell.setCellValue(op.getcontractNo()); nCell=nRow.createCell(cellNo++); nCell.setCellValue(op.getProductNo()); nCell=nRow.createCell(cellNo++); nCell.setCellValue(op.getCnumber()); nCell=nRow.createCell(cellNo++); nCell.setCellValue(op.getFactoryName()); nCell=nRow.createCell(cellNo++); nCell.setCellValue(op.getExts()); nCell=nRow.createCell(cellNo++); nCell.setCellValue(op.getDelivery_preriod()); nCell=nRow.createCell(cellNo++); nCell.setCellValue(op.getShip_time()); nCell=nRow.createCell(cellNo++); nCell.setCellValue(op.getTradeTerms()); } OutputStream os=new FileOutputStream(new File("F:\\outproduct.xls")); wb.write(os); os.close(); }
但是我们还需要修饰使表看起来更加好看,并添加下载链接,我们在下一篇继续讨论。
转载请注明出处:http://blog.csdn.net/acmman/article/details/48710311