此文主要是练习并学习ssh2,适用于初学者群体,大牛勿进,不喜勿喷!
主要解决有一下几个问题:
1.利用struts2的taglib标签库的iterator迭代生成多表单数据并存储,读取并添加跟新功能。
2.直接提取TXT的发票文件并上传解析存储
3.解决许多新手开发遇到的问题,架构已搭好,只需要专注于逻辑实现。
一.项目结构:
采用此demo的小伙伴最好不要更改项目结构,这是标准结构,因为可能加载的时候会因为包结构的问题导致找不到路径等~
二.项目结构的讲解
1.主体包
看主题路径分有一级包src和webroot:src内是类和方法包括mvc中的mc,处理业务问题等;webroot内包含的就是view的一些元素:jsp,css,js等,当然不是绝对的,但是这样不会有错。看波浪线的那个文件,必须要和src同级的,这就是为什么不建议修改主题结构的原因。
2.src的内容
src下面有structs.xml文件,主要是控制action的加载路径与界面跳转的问题。
由于invoice,purchaseOrder,salesOrder的业务逻辑是类似的,所以此处只来说一个:salesOrder。
action中的类主要是处理要进行的操作方法,所有方法都继承BaseAction(其中定义了一下基本操作和会话);
package com.mockservice.action;
import java.util.List;
import com.mockservice.model.Salesorder;
import com.mockservice.serviceImpl.SalesOrderServiceImpl;
public class SalesOrderAction extends BaseAction{
/**
*
*/
private static final long serialVersionUID = 1L;
private SalesOrderServiceImpl salesOrderService;
private String createDate;
private String createTime;
private String creater;
private String lastChangeDate;
private String lastChangeTime;
private String lastChanger;
private String customerId;
private String cusPurOrderId;
private String addressDescription;
private String postCode;
private String receiverName;
private String phoneNumber;
private int itemLine;
private String status;
List<Salesorder> listSO;
private int[] rows;
public String addSO(){
Salesorder salesOrder = new Salesorder();
salesOrder.setAddressDescription(addressDescription);
salesOrder.setCreateDate(createDate);
salesOrder.setCreater(creater);
salesOrder.setCreateTime(createTime);
salesOrder.setCusPurOrderId(cusPurOrderId);
salesOrder.setCustomerId(customerId);
salesOrder.setLastChangeDate(lastChangeDate);
salesOrder.setLastChanger(lastChanger);
salesOrder.setReceiverName(receiverName);
salesOrder.setPostCode(postCode);
salesOrder.setPhoneNumber(phoneNumber);
salesOrder.setLastChangeTime(lastChangeTime);
salesOrder.setItemLine(itemLine);
rows=new int[itemLine];
for(int i=0;i<itemLine;i++){
rows[i]=i;
}
salesOrder.setStatus(status);
salesOrderService.addSailesOrder(salesOrder);
return "addSalesSuccess";
}
public String getAllSO(){
listSO = salesOrderService.getAllSO();
return SUCCESS;
}
public String updateSOStatus(){
if(listSO.size()!=0 && listSO!=null){
salesOrderService.updateSOStatus(listSO);
}else{
return ERROR;
}
return SUCCESS;
}
public List<Salesorder> getListSO() {
return listSO;
}
public void setListSO(List<Salesorder> listSO) {
this.listSO = listSO;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public SalesOrderServiceImpl getSalesOrderService() {
return salesOrderService;
}
public void setSalesOrderService(SalesOrderServiceImpl salesOrderService) {
this.salesOrderService = salesOrderService;
}
public int getItemLine() {
return itemLine;
}
public void setItemLine(int itemLine) {
this.itemLine = itemLine;
}
public String getLastChanger() {
return lastChanger;
}
public void setLastChanger(String lastChanger) {
this.lastChanger = lastChanger;
}
public String getCustomerId() {
return customerId;
}
public void setCustomerId(String customerId) {
this.customerId = customerId;
}
public String getCusPurOrderId() {
return cusPurOrderId;
}
public void setCusPurOrderId(String cusPurOrderId) {
this.cusPurOrderId = cusPurOrderId;
}
public String getAddressDescription() {
return addressDescription;
}
public void setAddressDescription(String addressDescription) {
this.addressDescription = addressDescription;
}
public String getCreateDate() {
return createDate;
}
public void setCreateDate(String createDate) {
this.createDate = createDate;
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}