在这几天里,老师给我们分组,我们小组是实现,仓库管理
1.搭建ssh开发环境
2.写配置文件
3.分层实现
bean ——javaclass,xxx.hbm.xml
dao ——dao接口,实现
service——service接口,实现
action——action service dao

订单管理:1.订单编号
2.商品名称
3.商品价格
4.支付方式:在线支付 微信 货到付款
5.客户姓名
6.联系方式
7.送货地址
时间 dateyyyymmdd
time 时分秒
Date date=new date

库存管理
1.商品编号
2.商品名称
3.商品价格,售价,进价
4.进货渠道
5.库存数量

老师今天课上跟我们分享起自己的经验,说在写自己的代码时,要写注释,方便后来维护的人查错,找到负责这段代码的人,一般用自己中文名字缩写。

老师也告诉了我们我们一般出错误时候,404错误是路径错误,500错误是属性错误

在做库存管理的时候,步骤大致与客户信息管理相似,只多了一个生成excel的步骤,对于存进数据库的商品库存信息,可以通过GenerateExcelAction.java以及在DAO与Service中新增方法,在struts.xml和applicationContext.xml配置文件以及在kcInfo.jsp增加“生成EXCEL”按钮。配置如下:

package com.crm.service.impl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;


import com.crm.bean.Kc;
import com.crm.dao.KcDao;
import com.crm.service.KcService;

public class KcServiceImpl implements KcService{
KcDao kcDao; //定义了一个KcDao的对象

public KcDao getKcDao() {
return kcDao;
}

public void setKcDao(KcDao kcDao) {
this.kcDao = kcDao;
}

public List<Kc> findAllKc() {
// TODO Auto-generated method stub
return this.kcDao.findAllKc();
}

public Kc findKcById(Integer id) {
// TODO Auto-generated method stub
return this.kcDao.findKcById(id);
}

public void removeGoods(Kc kc) {
// TODO Auto-generated method stub
this.kcDao.removeGoods(kc);
}

public void saveGoods(Kc kc) {
// TODO Auto-generated method stub
this.kcDao.saveGoods(kc);

}
public void updateKc(Kc kc) {
// TODO Auto-generated method stub
this.kcDao.updateKc(kc);

}
public Object FindKcByCondition(Kc kc) {
// TODO Auto-generated method stub
return null;
}
public List<Kc> findKcByCondition(Kc kc) {
// TODO Auto-generated method stub
return this.kcDao.findKcByCondition(kc);
}
public Kc findGoodsById(Integer id) {
// TODO Auto-generated method stub
return this.kcDao.findKcById(id);
}
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.getGoodsno());

//
cell = row.createCell((short)1); //放置第二列商品名称的值
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(kc.getGoodsname());
//
cell = row.createCell((short)2); //放置第三列进货渠道的值
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
if("1".equals(kc.getSupply())){
cell.setCellValue("网上进货");
}else if("2".equals(kc.getSupply())){
cell.setCellValue("实体店进货");
}else if("3".equals(kc.getSupply())){
cell.setCellValue("其他");
}


//
cell = row.createCell((short)3); //放置第四列商品价格的值
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(kc.getPrice());

//
cell = row.createCell((short)4);//放置第五列商品的库存数量的值
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(kc.getInventory());
}
//根据输出流,输出到文件中
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;
}



}

最后 运行界面如下

 

 

充实的十天就要结束了 感谢李勇老师对我的指导!

posted on 2017-07-05 21:25  瓜皮秋秋  阅读(316)  评论(0编辑  收藏  举报