软工实践心得(3)

Jdk1.7  tomat6.0的环境下完成了这几天的学习,首先列出了之前做客户信息维护时遇到的问题,然后做了新的任务:库存信息管理。

一、之前遇到的问题

1.在修改过程中报错,为ArrayList的越界错误:数组超出索引。数组越界了,非法查询数组,大于或小于了数组的下标范围。需要检查下数组的访问。

 

2.UpdatePreviewCustAction.java中的custcustUpdate.jsp中的cust需要对应。而我原先写的customer导致数据库中cust的值为空值,所以修改总是出错。CustServiceImpl.java中的findCustomerById返回的总是空值,导致错误。

 

3.UpdateCustAction.java中的方法写错为customer,报错,以至于修改界面无法保存。

 

4.在显示电话号码这个功能时,缺少Cust.java中的电话号码的方法,增加后,得以显示。

 

5.Dao里面定义接口,用interface定义对象,查询的列表是一个集合,查询一个对象通过类的对象的id号,都是通过HibernateDaoSupport实现。

ActionSupport接受前端传过来的请求处理

404错误:路径错误

500错误:属性错误

 

二、之后的新项目:库存管理

接下来几天,我们分组做有关订单管理和库存管理的任务。我们主要做库存管理。

主要任务的流程就是以下几个方面

①撘环境 ssh

②写配置文件

③分层实现:

  1.BeanJava classxxx.hbm.xml

  2.DAODAO接口、DAO实现

  3.ServiceService接口、Service实现

  4.ActionActionServiceDAO

首先,订单管理的属性:

1.订单编号

2.商品名称

3.商品价格

4.支付方式:在线支付、微信、货到付款

5.客户姓名

6.联系方式

7.送货地址            

时间:Date ——年月日

      Time ——时分秒

库存管理:查看销售变化

1.商品编号

2.商品名称

3.商品价格:售价、进价

4.进货渠道

5.库存数量

JSPStruts:前端映射、后端Action映射

 

对于之后做出的库存管理,与之前做的客户信息维护大同小异,唯一有点区别的就是新增了excel表格,对于存进数据库的商品库存信息,可以通过GenerateExcelAction.java以及在DAOService中新增方法,在struts.xmlapplicationContext.xml配置文件以及在kcInfo.jsp增加“生成EXCEL”按钮。

GenerateExcelAction.java

package com.crm.action;

import java.io.InputStream;

import com.crm.service.KcService;

import com.opensymphony.xwork2.ActionSupport;

public class GenerateExcelAction extends ActionSupport {

private static final long serialVersionUID = 7213178640352795420L;

private KcService excelService;

public KcService getExcelService() {

return excelService;

}

public void setExcelService(KcService excelService) {

this.excelService = excelService;

}

public InputStream getDownloadFile(){

return this.excelService.getInputStream();

}

@Override

public String execute() throws Exception {

// TODO Auto-generated method stub

return SUCCESS;

}

}

applicationContext.xml

<!-- 导出excel -->

    <bean id="generateExcelAction" class="com.crm.action.GenerateExcelAction" scope="prototype">

    <property name="excelService">

      <ref bean="kcService"></ref>

    </property>

</bean>

struts.xml

<!-- 导出excel -->

<action name="generateExcel" class="generateExcelAction">

<result name="success" type="stream">

 <param name="contentType">application/vnd.ms-excel</param>

 <param name="contentDisposition">filename="AllKc.xls"</param>

 <param name="inputName">downloadFile</param>

</result>

</action>

KcServiceImpl.java

public InputStream getInputStream() {

//Apache poi hssf对象

HSSFWorkbook wb = new HSSFWorkbook();

//创建sheet

HSSFSheet sheet = wb.createSheet("sheet1");

//表头开始

//创建行

HSSFRow row = sheet.createRow(0);

//创建单元格 第一个单元格从零开始 第一列

HSSFCell cell = row.createCell((short)0);

//设置编码

cell.setEncoding(HSSFCell.ENCODING_UTF_16);

cell.setCellValue("商品编号");

//第二列

cell = row.createCell((short)1);

cell.setEncoding(HSSFCell.ENCODING_UTF_16);

cell.setCellValue("商品名称");

//第三列

cell = row.createCell((short)2);

cell.setEncoding(HSSFCell.ENCODING_UTF_16);

cell.setCellValue("商品价格");

//第四列

cell = row.createCell((short)3);

cell.setEncoding(HSSFCell.ENCODING_UTF_16);

cell.setCellValue("商品渠道");

//第五列

cell = row.createCell((short)4);

cell.setEncoding(HSSFCell.ENCODING_UTF_16);

cell.setCellValue("库存数量");

//表头结束

//查询数据库

List<Kc> list = this.kcDao.findAllKc();

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

Kc kc = list.get(i);

//把数据放到表格中

row = sheet.createRow(i+1);

cell = row.createCell((short)0);

cell.setEncoding(HSSFCell.ENCODING_UTF_16);

cell.setCellValue(kc.getProno());

 

//

cell = row.createCell((short)1);

cell.setEncoding(HSSFCell.ENCODING_UTF_16);

cell.setCellValue(kc.getProname());//设置表格序号

 

cell = row.createCell((short)2);

cell.setEncoding(HSSFCell.ENCODING_UTF_16);

cell.setCellValue(kc.getProprice());

 

cell = row.createCell((short)3);

cell.setEncoding(HSSFCell.ENCODING_UTF_16);

cell.setCellValue(kc.getSalechannel());

 

cell = row.createCell((short)4);

cell.setEncoding(HSSFCell.ENCODING_UTF_16);

cell.setCellValue(kc.getProquantity());

}

//根据输出流,输出到文件中

File file = new File("kc.xls");

try {

OutputStream os = new FileOutputStream(file);

//输出写入到文件中

wb.write(os);

//关闭输出流

os.close();

} catch (Exception e) {

e.printStackTrace();

}

InputStream is = null;

try {

is = new FileInputStream(file);

} catch (FileNotFoundException e) {

e.printStackTrace();

}

return is;

}

KcService.java

public InputStream getInputStream();

kcInfo.jsp

function funExcel(){

  location.href='generateExcel.action';

 };

<input width="100" type = "button"  value="生成excel" onClick="funExcel();"/>

<!--<s:a href="generateExcel.action">生成excel</s:a>-->

 

在页面上显示:

 

 

另外,我还增加了界面的背景图,就是在WebRoot中新建images,添加自己喜欢的图片,然后在jsp中添加一句代码 <body background="images/2.jpg">就会出来自己想要的界面。

 

posted @ 2017-07-05 19:49  蚂蚱先生在撅屁股  阅读(225)  评论(0编辑  收藏  举报