阅读SSH项目之ERP

计算机毕业设计Java前后端分离Erp系统(源代码+数据库+系统+lw文档) 计算机毕业设计Java前后端分离Erp系统(源代码+数据库+系统+lw文档)本源码技术栈:项目架构:B/S架构开发语言:Java语言开发软件:idea eclipse前端技术:Layui、HTML、CSS、JS、JQuery等技术后端技术:JAVA运行环境:Win10、JDK1.8数 据 库:MySQL5.7/8.0pwd=xy6w最新计算机专业原创开发毕业设计源码+数据库是近期作品 阅读详情

前言

本博文主要是记录我阅读过的SSH项目所学习到的知识,并不是相关系列教程。该SSH项目的gitHub地址:ERP项目地址

删除数据

实际业务中真正意义上的数据删除操作比较少见,多数情况是在数据中设置标记,通过标记的值来区分该数据是否可以用,而不是将数据真正的删除。

根据业务需求,为数据添加标记位,同时对数据的维护中添加启用/停用切换按钮,用于替换删除业务。所有的查询操作默认携带条件值为标记为可以的数据。除特殊业务外,标记为不可用的数据将不参与日常数据操作。

javaScript数值数据操作

javascript中如果需要对页面组件获取的值进行数字加操作,必须保障两个操作数据都是数字,否则将进行字符串连接运算。此处使用*1操作,将字符串快速转换为数字格式

代码生成器

由于我们的Dao、Service、Controller、配置文件都有很多重复的地方,我们可以通过“代码生成器”来将我们的文件生成出来。

package cn.itcast.erp.util.generator;import java.io.BufferedWriter;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.FileWriter;import java.io.InputStream;import java.lang.reflect.Field;import java.lang.reflect.Modifier;import cn.itcast.erp.invoice.operdetail.vo.OperDetailModel;public class GeneratorUtil {    private Class clazz;    private String b ;      //Emp    private String l ;      //e    private String s ;      //emp    private String pkg ;    //cn.itcast.erp.auth.emp    private String dir ;    //cn/itcast/erp/auth/emp/vo    public static void main(String[] args) throws Exception {        //EmpModel,RoleModel,ResModel,MenuModel        //SupplierModel,GoodsTypeModel,GoodsModel        //OrderModel,OrderDetailModel        //StoreModel,StoreDetailModel,OperDetailModel        new GeneratorUtil(OperDetailModel.class);        System.out.println("struts.xml未进行映射");        System.out.println("HbmXml未添加关联关系");        System.out.println("QueryModel未添加自定义范围查询条件");        System.out.println("DaoImpl中未对自定义查询条件形式条件设置");    }    public GeneratorUtil(Class clazz) throws Exception{        this.clazz = clazz;        //生成所有的内容        //-1.数据初始化        dataInit();        //0.创建目录        generatorDirectory();        //1.QueryModel        generatorQueryModel();        //2.Hbm.xml        generatorHbmXml();        //3.Dao        generatorDao();        //4.Impl        generatorImpl();        //5.Ebi        generatorEbi();        //6.Ebo        generatorEbo();        //7.Action        generatorAction();        //8.applicationContext.xml        generatorApplicationContextXml();        //9.struts.xml(选作)        //modifyStrutsXml();    }    private void modifyStrutsXml() throws Exception {        //1.读取原始的内容        //2.读取到特定位置(package)添加指定内容        //我们要读的文件与写的文件是同一个文件        /*        RandomAccessFile类读写文件时        读取,一共100,读70,写,写的内容会覆盖后30        111        222        333        444        在333的后面写5        111        222        333        544        在333的后面写5        111        222        333        555        */        //方案一:        /*        读取原始文件,将内容写入新文件        写之前判断,读取的内容是否是特定内容,特定内容写之前,加入新的内容        写完毕之后生成了新的文件,删除老的文件,使用新文件更名为老的文件        */        //方案二:        //1.读取原始文件的文件大小,字节总数1000        File f = new File("resources/struts.xml");        long len = f.length();        //2.创建一个字节数组,大小等于原始文件字节总数        byte[] buf = new byte[(int)len];        //3.将原始文件读入该byte数组        InputStream is = new FileInputStream(f);        is.read(buf);        is.close();        //4.将buf转化为字符串        String all = new String(buf);        //5.查找固定位置        int idx = all.lastIndexOf("    </package>");        //6.将要写入的内容插入该位置        String info = "     <!-- "+b+" -->\r\n      <action name=\""+s+"_*\" class=\""+s+"Action\" method=\"{1}\">\r\n      </action>\r\n\r\n";        //7.将info加入all的指定位置        StringBuilder sbf = new StringBuilder(all);        sbf.insert(idx, info);        //8.将sbf中的组合最终内容写入struts.xml        FileOutputStream fos = new FileOutputStream(f);        fos.write(sbf.toString().getBytes());        fos.close();    }    //8.applicationContext.xml    private void generatorApplicationContextXml() throws Exception {        File f = new File("resources/applicationContext-"+s+".xml");        if(f.exists()){            return;        }        f.createNewFile();        BufferedWriter bw = new BufferedWriter(new FileWriter(f));        bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");        bw.newLine();        bw.write("<beans xmlns=\"http://www.springframework.org/schema/beans\"");        bw.newLine();        bw.write("  xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");        bw.newLine();        bw.write("  xsi:schemaLocation=\"");        bw.newLine();        bw.write("      http://www.springframework.org/schema/beans ");        bw.newLine();        bw.write("      http://www.springframework.org/schema/beans/spring-beans.xsd");        bw.newLine();        bw.write("      \"> ");        bw.newLine();        bw.write("  <!-- Action -->");        bw.newLine();        bw.write("  <bean id=\""+s+"Action\" class=\""+pkg+".web."+b+"Action\" scope=\"prototype\">");        bw.newLine();        bw.write("      <property name=\""+s+"Ebi\" ref=\""+s+"Ebi\"/>");        bw.newLine();        bw.write("  </bean>");        bw.newLine();        bw.write("  <!-- Ebi -->");        bw.newLine();        bw.write("  <bean id=\""+s+"Ebi\" class=\""+pkg+".business.ebo."+b+"Ebo\">");        bw.newLine();        bw.write("      <property name=\""+s+"Dao\" ref=\""+s+"Dao\"/>");        bw.newLine();        bw.write("  </bean>");        bw.newLine();        bw.write("  <!-- Dao -->");        bw.newLine();        bw.write("  <bean id=\""+s+"Dao\" class=\""+pkg+".dao.impl."+b+"Impl\">");        bw.newLine();        bw.write("      <property name=\"sessionFactory\" ref=\"sessionFactory\"/>");        bw.newLine();        bw.write("  </bean>");        bw.newLine();        bw.write("</beans>");        bw.newLine();        bw.flush();        bw.close();             }    //7.Action    private void generatorAction() throws Exception {        File f = new File("src/"+dir+"/web/"+b+"Action.java");        if(f.exists()){            return;        }        f.createNewFile();        BufferedWriter bw = new BufferedWriter(new FileWriter(f));        bw.write("package "+pkg+".web;");        bw.newLine();        bw.newLine();        bw.write("import java.util.List;");        bw.newLine();        bw.newLine();        bw.write("import "+pkg+".business.ebi."+b+"Ebi;");        bw.newLine();        bw.write("import "+pkg+".vo."+b+"Model;");        bw.newLine();        bw.write("import "+pkg+".vo."+b+"QueryModel;");        bw.newLine();        bw.write("import cn.itcast.erp.util.base.BaseAction;");        bw.newLine();        bw.newLine();        bw.write("public class "+b+"Action extends BaseAction{");        bw.newLine();        bw.write("  public "+b+"Model "+l+"m = new "+b+"Model();");        bw.newLine();        bw.write("  public "+b+"QueryModel "+l+"qm = new "+b+"QueryModel();");        bw.newLine();        bw.newLine();        bw.write("  private "+b+"Ebi "+s+"Ebi;");        bw.newLine();        bw.write("  public void set"+b+"Ebi("+b+"Ebi "+s+"Ebi) {");        bw.newLine();        bw.write("      this."+s+"Ebi = "+s+"Ebi;");        bw.newLine();        bw.write("  }");        bw.newLine();        bw.newLine();        bw.write("  //列表");        bw.newLine();        bw.write("  public String list(){");        bw.newLine();        bw.write("      setDataTotal("+s+"Ebi.getCount("+l+"qm));");        bw.newLine();        bw.write("      List<"+b+"Model> "+s+"List = "+s+"Ebi.getAll("+l+"qm,pageNum,pageCount);");        bw.newLine();        bw.write("      put(\""+s+"List\", "+s+"List);");        bw.newLine();        bw.write("      return LIST;");        bw.newLine();        bw.write("  }");        bw.newLine();        bw.newLine();        bw.write("  //到添加");        bw.newLine();        bw.write("  public String input(){");        bw.newLine();        bw.write("      if("+l+"m.getUuid()!=null){");        bw.newLine();        bw.write("          "+l+"m = "+s+"Ebi.get("+l+"m.getUuid());");        bw.newLine();        bw.write("      }");        bw.newLine();        bw.write("      return INPUT;");        bw.newLine();        bw.write("  }");        bw.newLine();        bw.newLine();        bw.write("  //添加");        bw.newLine();        bw.write("  public String save(){");        bw.newLine();        bw.write("      if("+l+"m.getUuid() == null){");        bw.newLine();        bw.write("          "+s+"Ebi.save("+l+"m);");        bw.newLine();        bw.write("      }else{");        bw.newLine();        bw.write("          "+s+"Ebi.update("+l+"m);");        bw.newLine();        bw.write("      }");        bw.newLine();        bw.write("      return TO_LIST;");        bw.newLine();        bw.write("  }");        bw.newLine();        bw.newLine();        bw.write("  //删除");        bw.newLine();        bw.write("  public String delete(){");        bw.newLine();        bw.write("      "+s+"Ebi.delete("+l+"m);");        bw.newLine();        bw.write("      return TO_LIST;");        bw.newLine();        bw.write("  }");        bw.newLine();        bw.newLine();        bw.write("}");        bw.newLine();        bw.flush();        bw.close();             }    //6.Ebo    private void generatorEbo()  throws Exception {        File f = new File("src/"+dir+"/business/ebo/"+b+"Ebo.java");        if(f.exists()){            return;        }        f.createNewFile();        BufferedWriter bw = new BufferedWriter(new FileWriter(f));        bw.write("package "+pkg+".business.ebo;");        bw.newLine();        bw.newLine();        bw.write("import java.io.Serializable;");        bw.newLine();        bw.write("import java.util.List;");        bw.newLine();        bw.newLine();        bw.write("import "+pkg+".business.ebi."+b+"Ebi;");        bw.newLine();        bw.write("import "+pkg+".dao.dao."+b+"Dao;");        bw.newLine();        bw.write("import "+pkg+".vo."+b+"Model;");        bw.newLine();        bw.write("import cn.itcast.erp.util.base.BaseQueryModel;");        bw.newLine();        bw.newLine();        bw.write("public class "+b+"Ebo implements "+b+"Ebi{");        bw.newLine();        bw.write("  private "+b+"Dao "+s+"Dao;");        bw.newLine();        bw.write("  public void set"+b+"Dao("+b+"Dao "+s+"Dao) {");        bw.newLine();        bw.write("      this."+s+"Dao = "+s+"Dao;");        bw.newLine();        bw.write("  }");        bw.newLine();        bw.newLine();        bw.write("  public void save("+b+"Model "+l+"m) {");        bw.newLine();        bw.write("      "+s+"Dao.save("+l+"m);");        bw.newLine();        bw.write("  }");        bw.newLine();        bw.newLine();        bw.write("  public void update("+b+"Model "+l+"m) {");        bw.newLine();        bw.write("      "+s+"Dao.update("+l+"m);");        bw.newLine();        bw.write("  }");        bw.newLine();        bw.newLine();        bw.write("  public void delete("+b+"Model "+l+"m) {");        bw.newLine();        bw.write("      "+s+"Dao.delete("+l+"m);");        bw.newLine();        bw.write("  }");        bw.newLine();        bw.newLine();        bw.write("  public "+b+"Model get(Serializable uuid) {");        bw.newLine();        bw.write("      return "+s+"Dao.get(uuid);");        bw.newLine();        bw.write("  }");        bw.newLine();        bw.newLine();        bw.write("  public List<"+b+"Model> getAll() {");        bw.newLine();        bw.write("      return "+s+"Dao.getAll();");        bw.newLine();        bw.write("  }");        bw.newLine();        bw.newLine();        bw.write("  public List<"+b+"Model> getAll(BaseQueryModel qm, Integer pageNum,Integer pageCount) {");        bw.newLine();        bw.write("      return "+s+"Dao.getAll(qm,pageNum,pageCount);");        bw.newLine();        bw.write("  }");        bw.newLine();        bw.newLine();        bw.write("  public Integer getCount(BaseQueryModel qm) {");        bw.newLine();        bw.write("      return "+s+"Dao.getCount(qm);");        bw.newLine();        bw.write("  }");        bw.newLine();        bw.newLine();        bw.write("}");        bw.newLine();        bw.flush();        bw.close();             }    //5.Ebi    private void generatorEbi()  throws Exception {        File f = new File("src/"+dir+"/business/ebi/"+b+"Ebi.java");        if(f.exists()){            return;        }        f.createNewFile();        BufferedWriter bw = new BufferedWriter(new FileWriter(f));        bw.write("package "+pkg+".business.ebi;");        bw.newLine();        bw.newLine();        bw.write("import org.springframework.transaction.annotation.Transactional;");        bw.newLine();        bw.newLine();        bw.write("import "+pkg+".vo."+b+"Model;");        bw.newLine();        bw.write("import cn.itcast.erp.util.base.BaseEbi;");        bw.newLine();        bw.newLine();        bw.write("@Transactional");        bw.newLine();        bw.write("public interface "+b+"Ebi extends BaseEbi<"+b+"Model>{");        bw.newLine();        bw.newLine();        bw.write("}");        bw.newLine();        bw.flush();        bw.close();     }    //4.Impl    private void generatorImpl()  throws Exception {        File f = new File("src/"+dir+"/dao/impl/"+b+"Impl.java");        if(f.exists()){            return;        }        f.createNewFile();        BufferedWriter bw = new BufferedWriter(new FileWriter(f));        bw.write("package "+pkg+".dao.impl;");        bw.newLine();        bw.newLine();        bw.write("import org.hibernate.criterion.DetachedCriteria;");        bw.newLine();        bw.write("import org.hibernate.criterion.Restrictions;");        bw.newLine();        bw.newLine();        bw.write("import "+pkg+".dao.dao."+b+"Dao;");        bw.newLine();        bw.write("import "+pkg+".vo."+b+"Model;");        bw.newLine();        bw.write("import "+pkg+".vo."+b+"QueryModel;");        bw.newLine();        bw.write("import cn.itcast.erp.util.base.BaseImpl;");        bw.newLine();        bw.write("import cn.itcast.erp.util.base.BaseQueryModel;");        bw.newLine();        bw.newLine();        bw.write("public class "+b+"Impl extends BaseImpl<"+b+"Model> implements "+b+"Dao{");        bw.newLine();        bw.newLine();        bw.write("  public void doQbc(DetachedCriteria dc,BaseQueryModel qm){");        bw.newLine();        bw.write("      "+b+"QueryModel "+l+"qm = ("+b+"QueryModel)qm;");        bw.newLine();        bw.write("      // TODO 添加自定义查询条件");        bw.newLine();        bw.write("  }");        bw.newLine();        bw.newLine();        bw.write("}");        bw.newLine();        bw.flush();        bw.close();         }    //3.Dao    private void generatorDao() throws Exception {        File f = new File("src/"+dir+"/dao/dao/"+b+"Dao.java");        if(f.exists()){            return;        }        f.createNewFile();        BufferedWriter bw = new BufferedWriter(new FileWriter(f));        bw.write("package "+pkg+".dao.dao;");        bw.newLine();        bw.newLine();        bw.write("import "+pkg+".vo."+b+"Model;");        bw.newLine();        bw.write("import cn.itcast.erp.util.base.BaseDao;");        bw.newLine();        bw.newLine();        bw.write("public interface "+b+"Dao extends BaseDao<"+b+"Model> {");        bw.newLine();        bw.newLine();        bw.write("}");        bw.newLine();        bw.flush();        bw.close();         }    //2.Hbm.xml    private void generatorHbmXml() throws Exception {        //1.创建文件        File f = new File("src/"+dir+"/vo/"+b+"Model.hbm.xml");        if(f.exists()){            return;        }        f.createNewFile();        //2.IO写入内容        BufferedWriter bw = new BufferedWriter(new FileWriter(f));        bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");        bw.newLine();        bw.write("<!DOCTYPE hibernate-mapping PUBLIC");        bw.newLine();        bw.write("        '-//Hibernate/Hibernate Mapping DTD 3.0//EN'");        bw.newLine();        bw.write("        'http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd'>");        bw.newLine();        bw.write("<hibernate-mapping>");        bw.newLine();        bw.write("    <class name=\""+pkg+".vo."+b+"Model\" table=\"tbl_"+s+"\">");        bw.newLine();        bw.write("        <id name=\"uuid\">");        bw.newLine();        bw.write("            <generator class=\"native\" />");        bw.newLine();        bw.write("        </id>");        bw.newLine();        //hibernate的映射配置文件中要对原始模型类中的属性进行配置,反射获取所有字段        Field[] fds = clazz.getDeclaredFields();        for(Field fd:fds) {            //如果字段的修饰符是private,生成            if(fd.getModifiers() == Modifier.PRIVATE && !fd.getName().equals("uuid")){                //如果是关联关系不生成,不是关联关系(Long,Integer,Double,String)                if( fd.getType().equals(String.class)||                    fd.getType().equals(Long.class)||                    fd.getType().equals(Integer.class)||                    fd.getType().equals(Double.class)                    ){                    if(!fd.getName().endsWith("View")){                        bw.write("        <property name=\""+fd.getName()+"\"/>");                        bw.newLine();                    }                }            }        }        bw.write("    </class>");        bw.newLine();        bw.write("</hibernate-mapping>");        bw.newLine();        bw.flush();        bw.close();         }    //1.QueryModel    private void generatorQueryModel() throws Exception {        //1.创建文件        File f = new File("src/"+dir+"/vo/"+b+"QueryModel.java");        //判断:如果该文件存在,终止操作        if(f.exists()){            return;        }        f.createNewFile();        //2.IO写入内容        BufferedWriter bw = new BufferedWriter(new FileWriter(f));        bw.write("package "+pkg+".vo;");        bw.newLine();        bw.newLine();        bw.write("import cn.itcast.erp.util.base.BaseQueryModel;");        bw.newLine();        bw.newLine();        bw.write("public class "+b+"QueryModel extends "+b+"Model implements BaseQueryModel{");        bw.newLine();        bw.write("  // TODO 添加自定义查询条件");        bw.newLine();        bw.write("}");        bw.newLine();        bw.flush();        bw.close();    }    //0.创建目录    private void generatorDirectory() {        //business/ebi        //               src+//cn.itcast.erp.auth.emp+business/ebi .vo        File f = new File("src/"+dir+"/business/ebi");        f.mkdirs();        //business/ebo        f = new File("src/"+dir+"/business/ebo");        f.mkdirs();        //dao/dao        f = new File("src/"+dir+"/dao/dao");        f.mkdirs();        //dao/impl        f = new File("src/"+dir+"/dao/impl");        f.mkdirs();        //web        f = new File("src/"+dir+"/web");        f.mkdirs();    }    //-1.数据初始化    private void dataInit() {        String className = clazz.getSimpleName();                   //EmpModel        b = className.substring(0, className.length()-5);   //Emp        String first = b.substring(0,1);                            //E        l = first.toLowerCase();                        //e        s = l+b.substring(1);                       //emp        String rootPkg = clazz.getPackage().getName();              //cn.itcast.erp.auth.emp.vo        pkg = rootPkg.substring(0,rootPkg.length()-3);      //cn.itcast.erp.auth.emp        dir = pkg.replace(".","/");                         //cn/itcast/erp/auth/emp/vo    }    /*    public static void main(String[] args) throws Exception {        //核心工作原理:文件IO+反射        File f = new File("src/EmpAction.java");        f.createNewFile();        BufferedWriter bw = new BufferedWriter(new FileWriter(f));        bw.write("public class EmpAction{}");        bw.flush();        bw.close();    }    */}

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

import cn.itcast.erp.invoice.operdetail.vo.OperDetailModel;

public class GeneratorUtil {
   private Class clazz;
   private String b ;      //Emp
   private String l ;      //e
   private String s ;      //emp
   private String pkg ;    //cn.itcast.erp.auth.emp
   private String dir ;    //cn/itcast/erp/auth/emp/vo

   public static void main(String[] args) throws Exception {
       //EmpModel,RoleModel,ResModel,MenuModel
       //SupplierModel,GoodsTypeModel,GoodsModel
       //OrderModel,OrderDetailModel
       //StoreModel,StoreDetailModel,OperDetailModel
       new GeneratorUtil(OperDetailModel.class);
       System.out.println("struts.xml未进行映射");
       System.out.println("HbmXml未添加关联关系");
       System.out.println("QueryModel未添加自定义范围查询条件");
       System.out.println("DaoImpl中未对自定义查询条件形式条件设置");
   }

   public GeneratorUtil(Class clazz) throws Exception{
       this.clazz = clazz;
       //生成所有的内容
       //-1.数据初始化
       dataInit();
       //0.创建目录
       generatorDirectory();
       //1.QueryModel
       generatorQueryModel();
       //2.Hbm.xml
       generatorHbmXml();
       //3.Dao
       generatorDao();
       //4.Impl
       generatorImpl();
       //5.Ebi
       generatorEbi();
       //6.Ebo
       generatorEbo();
       //7.Action
       generatorAction();
       //8.applicationContext.xml
       generatorApplicationContextXml();
       //9.struts.xml(选作)
       //modifyStrutsXml();
   }

   private void modifyStrutsXml() throws Exception {
       //1.读取原始的内容
       //2.读取到特定位置(package)添加指定内容

       //我们要读的文件与写的文件是同一个文件
       /*
       RandomAccessFile类读写文件时
       读取,一共100,读70,写,写的内容会覆盖后30
       111
       222
       333
       444
       在333的后面写5
       111
       222
       333
       544
       在333的后面写5
       111
       222
       333
       555
       */

       //方案一:
       /*
       读取原始文件,将内容写入新文件
       写之前判断,读取的内容是否是特定内容,特定内容写之前,加入新的内容
       写完毕之后生成了新的文件,删除老的文件,使用新文件更名为老的文件
       */

       //方案二:
       //1.读取原始文件的文件大小,字节总数1000
       File f = new File("resources/struts.xml");
       long len = f.length();
       //2.创建一个字节数组,大小等于原始文件字节总数
       byte[] buf = new byte[(int)len];
       //3.将原始文件读入该byte数组
       InputStream is = new FileInputStream(f);
       is.read(buf);
       is.close();
       //4.将buf转化为字符串
       String all = new String(buf);
       //5.查找固定位置
       int idx = all.lastIndexOf("    </package>");
       //6.将要写入的内容插入该位置
       String info = "     <!-- "+b+" -->\r\n      <action name=\""+s+"_*\" class=\""+s+"Action\" method=\"{1}\">\r\n      </action>\r\n\r\n";
       //7.将info加入all的指定位置
       StringBuilder sbf = new StringBuilder(all);
       sbf.insert(idx, info);
       //8.将sbf中的组合最终内容写入struts.xml
       FileOutputStream fos = new FileOutputStream(f);
       fos.write(sbf.toString().getBytes());
       fos.close();
   }

   //8.applicationContext.xml
   private void generatorApplicationContextXml() throws Exception {
       File f = new File("resources/applicationContext-"+s+".xml");
       if(f.exists()){
           return;
       }
       f.createNewFile();
       BufferedWriter bw = new BufferedWriter(new FileWriter(f));

       bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
       bw.newLine();

       bw.write("<beans xmlns=\"http://www.springframework.org/schema/beans\"");
       bw.newLine();

       bw.write("  xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
       bw.newLine();

       bw.write("  xsi:schemaLocation=\"");
       bw.newLine();

       bw.write("      http://www.springframework.org/schema/beans ");
       bw.newLine();

       bw.write("      http://www.springframework.org/schema/beans/spring-beans.xsd");
       bw.newLine();

       bw.write("      \"> ");
       bw.newLine();

       bw.write("  <!-- Action -->");
       bw.newLine();

       bw.write("  <bean id=\""+s+"Action\" class=\""+pkg+".web."+b+"Action\" scope=\"prototype\">");
       bw.newLine();

       bw.write("      <property name=\""+s+"Ebi\" ref=\""+s+"Ebi\"/>");
       bw.newLine();

       bw.write("  </bean>");
       bw.newLine();

       bw.write("  <!-- Ebi -->");
       bw.newLine();

       bw.write("  <bean id=\""+s+"Ebi\" class=\""+pkg+".business.ebo."+b+"Ebo\">");
       bw.newLine();

       bw.write("      <property name=\""+s+"Dao\" ref=\""+s+"Dao\"/>");
       bw.newLine();

       bw.write("  </bean>");
       bw.newLine();

       bw.write("  <!-- Dao -->");
       bw.newLine();

       bw.write("  <bean id=\""+s+"Dao\" class=\""+pkg+".dao.impl."+b+"Impl\">");
       bw.newLine();

       bw.write("      <property name=\"sessionFactory\" ref=\"sessionFactory\"/>");
       bw.newLine();

       bw.write("  </bean>");
       bw.newLine();

       bw.write("</beans>");
       bw.newLine();

       bw.flush();
       bw.close();        
   }

   //7.Action
   private void generatorAction() throws Exception {
       File f = new File("src/"+dir+"/web/"+b+"Action.java");
       if(f.exists()){
           return;
       }
       f.createNewFile();
       BufferedWriter bw = new BufferedWriter(new FileWriter(f));

       bw.write("package "+pkg+".web;");
       bw.newLine();

       bw.newLine();

       bw.write("import java.util.List;");
       bw.newLine();

       bw.newLine();

       bw.write("import "+pkg+".business.ebi."+b+"Ebi;");
       bw.newLine();

       bw.write("import "+pkg+".vo."+b+"Model;");
       bw.newLine();

       bw.write("import "+pkg+".vo."+b+"QueryModel;");
       bw.newLine();

       bw.write("import cn.itcast.erp.util.base.BaseAction;");
       bw.newLine();

       bw.newLine();

       bw.write("public class "+b+"Action extends BaseAction{");
       bw.newLine();

       bw.write("  public "+b+"Model "+l+"m = new "+b+"Model();");
       bw.newLine();

       bw.write("  public "+b+"QueryModel "+l+"qm = new "+b+"QueryModel();");
       bw.newLine();

       bw.newLine();

       bw.write("  private "+b+"Ebi "+s+"Ebi;");
       bw.newLine();

       bw.write("  public void set"+b+"Ebi("+b+"Ebi "+s+"Ebi) {");
       bw.newLine();

       bw.write("      this."+s+"Ebi = "+s+"Ebi;");
       bw.newLine();

       bw.write("  }");
       bw.newLine();

       bw.newLine();

       bw.write("  //列表");
       bw.newLine();

       bw.write("  public String list(){");
       bw.newLine();

       bw.write("      setDataTotal("+s+"Ebi.getCount("+l+"qm));");
       bw.newLine();

       bw.write("      List<"+b+"Model> "+s+"List = "+s+"Ebi.getAll("+l+"qm,pageNum,pageCount);");
       bw.newLine();

       bw.write("      put(\""+s+"List\", "+s+"List);");
       bw.newLine();

       bw.write("      return LIST;");
       bw.newLine();

       bw.write("  }");
       bw.newLine();

       bw.newLine();

       bw.write("  //到添加");
       bw.newLine();

       bw.write("  public String input(){");
       bw.newLine();

       bw.write("      if("+l+"m.getUuid()!=null){");
       bw.newLine();

       bw.write("          "+l+"m = "+s+"Ebi.get("+l+"m.getUuid());");
       bw.newLine();

       bw.write("      }");
       bw.newLine();

       bw.write("      return INPUT;");
       bw.newLine();

       bw.write("  }");
       bw.newLine();

       bw.newLine();

       bw.write("  //添加");
       bw.newLine();

       bw.write("  public String save(){");
       bw.newLine();

       bw.write("      if("+l+"m.getUuid() == null){");
       bw.newLine();

       bw.write("          "+s+"Ebi.save("+l+"m);");
       bw.newLine();

       bw.write("      }else{");
       bw.newLine();

       bw.write("          "+s+"Ebi.update("+l+"m);");
       bw.newLine();

       bw.write("      }");
       bw.newLine();

       bw.write("      return TO_LIST;");
       bw.newLine();

       bw.write("  }");
       bw.newLine();

       bw.newLine();

       bw.write("  //删除");
       bw.newLine();

       bw.write("  public String delete(){");
       bw.newLine();

       bw.write("      "+s+"Ebi.delete("+l+"m);");
       bw.newLine();

       bw.write("      return TO_LIST;");
       bw.newLine();

       bw.write("  }");
       bw.newLine();

       bw.newLine();

       bw.write("}");
       bw.newLine();

       bw.flush();
       bw.close();        
   }

   //6.Ebo
   private void generatorEbo()  throws Exception {
       File f = new File("src/"+dir+"/business/ebo/"+b+"Ebo.java");
       if(f.exists()){
           return;
       }
       f.createNewFile();
       BufferedWriter bw = new BufferedWriter(new FileWriter(f));

       bw.write("package "+pkg+".business.ebo;");
       bw.newLine();

       bw.newLine();

       bw.write("import java.io.Serializable;");
       bw.newLine();

       bw.write("import java.util.List;");
       bw.newLine();

       bw.newLine();

       bw.write("import "+pkg+".business.ebi."+b+"Ebi;");
       bw.newLine();

       bw.write("import "+pkg+".dao.dao."+b+"Dao;");
       bw.newLine();

       bw.write("import "+pkg+".vo."+b+"Model;");
       bw.newLine();

       bw.write("import cn.itcast.erp.util.base.BaseQueryModel;");
       bw.newLine();

       bw.newLine();

       bw.write("public class "+b+"Ebo implements "+b+"Ebi{");
       bw.newLine();

       bw.write("  private "+b+"Dao "+s+"Dao;");
       bw.newLine();

       bw.write("  public void set"+b+"Dao("+b+"Dao "+s+"Dao) {");
       bw.newLine();

       bw.write("      this."+s+"Dao = "+s+"Dao;");
       bw.newLine();

       bw.write("  }");
       bw.newLine();

       bw.newLine();

       bw.write("  public void save("+b+"Model "+l+"m) {");
       bw.newLine();

       bw.write("      "+s+"Dao.save("+l+"m);");
       bw.newLine();

       bw.write("  }");
       bw.newLine();

       bw.newLine();

       bw.write("  public void update("+b+"Model "+l+"m) {");
       bw.newLine();

       bw.write("      "+s+"Dao.update("+l+"m);");
       bw.newLine();

       bw.write("  }");
       bw.newLine();

       bw.newLine();

       bw.write("  public void delete("+b+"Model "+l+"m) {");
       bw.newLine();

       bw.write("      "+s+"Dao.delete("+l+"m);");
       bw.newLine();

       bw.write("  }");
       bw.newLine();

       bw.newLine();

       bw.write("  public "+b+"Model get(Serializable uuid) {");
       bw.newLine();

       bw.write("      return "+s+"Dao.get(uuid);");
       bw.newLine();

       bw.write("  }");
       bw.newLine();

       bw.newLine();

       bw.write("  public List<"+b+"Model> getAll() {");
       bw.newLine();

       bw.write("      return "+s+"Dao.getAll();");
       bw.newLine();

       bw.write("  }");
       bw.newLine();

       bw.newLine();

       bw.write("  public List<"+b+"Model> getAll(BaseQueryModel qm, Integer pageNum,Integer pageCount) {");
       bw.newLine();

       bw.write("      return "+s+"Dao.getAll(qm,pageNum,pageCount);");
       bw.newLine();

       bw.write("  }");
       bw.newLine();

       bw.newLine();

       bw.write("  public Integer getCount(BaseQueryModel qm) {");
       bw.newLine();

       bw.write("      return "+s+"Dao.getCount(qm);");
       bw.newLine();

       bw.write("  }");
       bw.newLine();

       bw.newLine();

       bw.write("}");
       bw.newLine();

       bw.flush();
       bw.close();        
   }

   //5.Ebi
   private void generatorEbi()  throws Exception {
       File f = new File("src/"+dir+"/business/ebi/"+b+"Ebi.java");
       if(f.exists()){
           return;
       }
       f.createNewFile();
       BufferedWriter bw = new BufferedWriter(new FileWriter(f));

       bw.write("package "+pkg+".business.ebi;");
       bw.newLine();

       bw.newLine();

       bw.write("import org.springframework.transaction.annotation.Transactional;");
       bw.newLine();

       bw.newLine();

       bw.write("import "+pkg+".vo."+b+"Model;");
       bw.newLine();

       bw.write("import cn.itcast.erp.util.base.BaseEbi;");
       bw.newLine();

       bw.newLine();

       bw.write("@Transactional");
       bw.newLine();

       bw.write("public interface "+b+"Ebi extends BaseEbi<"+b+"Model>{");
       bw.newLine();

       bw.newLine();

       bw.write("}");
       bw.newLine();

       bw.flush();
       bw.close();
   }

   //4.Impl
   private void generatorImpl()  throws Exception {
       File f = new File("src/"+dir+"/dao/impl/"+b+"Impl.java");
       if(f.exists()){
           return;
       }
       f.createNewFile();
       BufferedWriter bw = new BufferedWriter(new FileWriter(f));

       bw.write("package "+pkg+".dao.impl;");
       bw.newLine();

       bw.newLine();

       bw.write("import org.hibernate.criterion.DetachedCriteria;");
       bw.newLine();

       bw.write("import org.hibernate.criterion.Restrictions;");
       bw.newLine();

       bw.newLine();

       bw.write("import "+pkg+".dao.dao."+b+"Dao;");
       bw.newLine();

       bw.write("import "+pkg+".vo."+b+"Model;");
       bw.newLine();

       bw.write("import "+pkg+".vo."+b+"QueryModel;");
       bw.newLine();

       bw.write("import cn.itcast.erp.util.base.BaseImpl;");
       bw.newLine();

       bw.write("import cn.itcast.erp.util.base.BaseQueryModel;");
       bw.newLine();

       bw.newLine();

       bw.write("public class "+b+"Impl extends BaseImpl<"+b+"Model> implements "+b+"Dao{");
       bw.newLine();

       bw.newLine();

       bw.write("  public void doQbc(DetachedCriteria dc,BaseQueryModel qm){");
       bw.newLine();

       bw.write("      "+b+"QueryModel "+l+"qm = ("+b+"QueryModel)qm;");
       bw.newLine();

       bw.write("      // TODO 添加自定义查询条件");
       bw.newLine();

       bw.write("  }");
       bw.newLine();

       bw.newLine();

       bw.write("}");
       bw.newLine();

       bw.flush();
       bw.close();    
   }

   //3.Dao
   private void generatorDao() throws Exception {
       File f = new File("src/"+dir+"/dao/dao/"+b+"Dao.java");
       if(f.exists()){
           return;
       }
       f.createNewFile();
       BufferedWriter bw = new BufferedWriter(new FileWriter(f));

       bw.write("package "+pkg+".dao.dao;");
       bw.newLine();

       bw.newLine();

       bw.write("import "+pkg+".vo."+b+"Model;");
       bw.newLine();

       bw.write("import cn.itcast.erp.util.base.BaseDao;");
       bw.newLine();

       bw.newLine();

       bw.write("public interface "+b+"Dao extends BaseDao<"+b+"Model> {");
       bw.newLine();

       bw.newLine();

       bw.write("}");
       bw.newLine();

       bw.flush();
       bw.close();    
   }

   //2.Hbm.xml
   private void generatorHbmXml() throws Exception {
       //1.创建文件
       File f = new File("src/"+dir+"/vo/"+b+"Model.hbm.xml");

       if(f.exists()){
           return;
       }

       f.createNewFile();
       //2.IO写入内容
       BufferedWriter bw = new BufferedWriter(new FileWriter(f));

       bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
       bw.newLine();

       bw.write("<!DOCTYPE hibernate-mapping PUBLIC");
       bw.newLine();

       bw.write("        '-//Hibernate/Hibernate Mapping DTD 3.0//EN'");
       bw.newLine();

       bw.write("        'http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd'>");
       bw.newLine();

       bw.write("<hibernate-mapping>");
       bw.newLine();

       bw.write("    <class name=\""+pkg+".vo."+b+"Model\" table=\"tbl_"+s+"\">");
       bw.newLine();

       bw.write("        <id name=\"uuid\">");
       bw.newLine();

       bw.write("            <generator class=\"native\" />");
       bw.newLine();

       bw.write("        </id>");
       bw.newLine();

       //hibernate的映射配置文件中要对原始模型类中的属性进行配置,反射获取所有字段
       Field[] fds = clazz.getDeclaredFields();
       for(Field fd:fds) {
           //如果字段的修饰符是private,生成
           if(fd.getModifiers() == Modifier.PRIVATE && !fd.getName().equals("uuid")){
               //如果是关联关系不生成,不是关联关系(Long,Integer,Double,String)
               if( fd.getType().equals(String.class)||
                   fd.getType().equals(Long.class)||
                   fd.getType().equals(Integer.class)||
                   fd.getType().equals(Double.class)
                   ){
                   if(!fd.getName().endsWith("View")){
                       bw.write("        <property name=\""+fd.getName()+"\"/>");
                       bw.newLine();
                   }
               }
           }
       }

       bw.write("    </class>");
       bw.newLine();

       bw.write("</hibernate-mapping>");
       bw.newLine();

       bw.flush();
       bw.close();    
   }

   //1.QueryModel
   private void generatorQueryModel() throws Exception {
       //1.创建文件
       File f = new File("src/"+dir+"/vo/"+b+"QueryModel.java");

       //判断:如果该文件存在,终止操作
       if(f.exists()){
           return;
       }

       f.createNewFile();
       //2.IO写入内容
       BufferedWriter bw = new BufferedWriter(new FileWriter(f));

       bw.write("package "+pkg+".vo;");
       bw.newLine();

       bw.newLine();

       bw.write("import cn.itcast.erp.util.base.BaseQueryModel;");
       bw.newLine();

       bw.newLine();

       bw.write("public class "+b+"QueryModel extends "+b+"Model implements BaseQueryModel{");
       bw.newLine();

       bw.write("  // TODO 添加自定义查询条件");
       bw.newLine();

       bw.write("}");
       bw.newLine();

       bw.flush();
       bw.close();
   }

   //0.创建目录
   private void generatorDirectory() {
       //business/ebi
       //               src+//cn.itcast.erp.auth.emp+business/ebi .vo
       File f = new File("src/"+dir+"/business/ebi");
       f.mkdirs();
       //business/ebo
       f = new File("src/"+dir+"/business/ebo");
       f.mkdirs();
       //dao/dao
       f = new File("src/"+dir+"/dao/dao");
       f.mkdirs();
       //dao/impl
       f = new File("src/"+dir+"/dao/impl");
       f.mkdirs();
       //web
       f = new File("src/"+dir+"/web");
       f.mkdirs();
   }

   //-1.数据初始化
   private void dataInit() {
       String className = clazz.getSimpleName();                   //EmpModel
       b = className.substring(0, className.length()-5);   //Emp
       String first = b.substring(0,1);                            //E
       l = first.toLowerCase();                        //e
       s = l+b.substring(1);                       //emp
       String rootPkg = clazz.getPackage().getName();              //cn.itcast.erp.auth.emp.vo
       pkg = rootPkg.substring(0,rootPkg.length()-3);      //cn.itcast.erp.auth.emp
       dir = pkg.replace(".","/");                         //cn/itcast/erp/auth/emp/vo
   }

   /*
   public static void main(String[] args) throws Exception {
       //核心工作原理:文件IO+反射
       File f = new File("src/EmpAction.java");
       f.createNewFile();

       BufferedWriter bw = new BufferedWriter(new FileWriter(f));
       bw.write("public class EmpAction{}");
       bw.flush();
       bw.close();
   }
   */

}

拦截器捕获异常

一般地,我们都是Dao、servcie层都把异常抛出,最后由Action来进行捕获。如果所有的Action都要捕获异常的话,那么就多了很多的重复代码。

因此,我们可以使用拦截器来进行统一捕获。

修改角色权限无法同步的问题

如果用户已经登录,此时修改登录用户的角色信息或角色对应的资源信息。由于用户的数据已经存在于Session中,无法及时进行数据同步。

解决方案:

在ServletContext范围内设置集合变量changeEmp,当管理员维护到某个员工的角色时,将该员工的OID放入该集合;

当管理员维护到某个角色的资源时,将该角色对应的所有员工OID放入该集合。

在登录校验时,获取完登录信息后,再次获取该集合,查看当前用户OID是否存在于该集合。如果存在于该集合中,清空当前登录人信息,将员工OID从集合中删除,同时跳转到登录界面。

配置数据源

一般地,我们做开发都是直接使用tomcat来连接数据库,但是如果数据库的地址变化的时候,我们就要手动去修改连接的地址了。这样会造成一些不必要的麻烦。

640?wx_fmt=png

所以,官方是推荐我们使用JNDI来配置数据源,使用JNDI来连接数据库的。这样即使数据库的地址变了,我们就不用手动去修改连接的地址。

步骤如下:

    <Resource         name="jdbc/DataSource"         auth="Container"         type="javax.sql.DataSource"        maxActive="100"         maxIdle="30"         maxWait="10000"        url="jdbc:mysql://localhost:3306/erpdb"        driverClassName="com.mysql.jdbc.Driver"        username="root"         password="root"     />
    <resource-ref>        <res-ref-name>jdbc/DataSource</res-ref-name>        <res-type>javax.sql.DataSource</res-type>        <res-auth>Container</res-auth>    </resource-ref>
       <res-ref-name>jdbc/DataSource</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
   </resource-ref>
640?wx_fmt=png

JNDI的命名,不同web服务器有不同的书写格式:

JNDI名是远端访问的通用名称,可以理解为使用该名称获取对应的资源信息。JNDI的命名官方规范        java:comp/env/JNDI名称Jboss    java:JNDI名称Weblogic    JNDI名称
Jboss    java:JNDI名称
Weblogic    JNDI名称

权限控制菜单树

每个菜单树需要的权限可能是不一样的,要想用权限系统去管理菜单树,就要把菜单树写成是动态的。

640?wx_fmt=png

菜单模型设计如下:

在查询的时候用到了自关联

640?wx_fmt=png

商品联动

640?wx_fmt=png

在页面加载的时候,查询出所有供应商的数据、查询第一个供应商商品的类别以及第一个商品类别对应的所有信息集合。那么在页面上我们就可以将其展示出来了。

随后如果发生了改变的话,那么还是使用ajax来进行联动。

在添加新项的时候,对应的联动还是需要保持的,因此需要在外面套一层ajax来获取具体的数据!

640?wx_fmt=png
    //吐槽一下,这代码看得我贼鸡儿恶心,逻辑是这样子的:    //首先在新增的时候我们要新增出新行的页面。    //同时下拉框的数据需要与数据库后台进行联动    //并且只能动态添加不同名称的商品,类别下所有商品已经存在了,那么就不能选择该类别了。    //还要对其不能随便修改,否则相同类型相同名称的商品又存在了。    // HTML+Jquery的拼接看得十分蛋疼....

   //首先在新增的时候我们要新增出新行的页面。
   //同时下拉框的数据需要与数据库后台进行联动
   //并且只能动态添加不同名称的商品,类别下所有商品已经存在了,那么就不能选择该类别了。
   //还要对其不能随便修改,否则相同类型相同名称的商品又存在了。
   // HTML+Jquery的拼接看得十分蛋疼....
//添加新商品        $("#add").click(function () {            //设置不能修改供应商            $("#supplier").attr("disabled", "disabled");            //设置已存在的所有select全部不可点击            $(".goodsType").attr("disabled", "disabled");            $(".goods").attr("disabled", "disabled");            //发送ajax提交,将供应商id与当前已经使用的类别对应商品2个id传递到后台,并将其过滤,过滤完毕的数据传递回页面            var goodsTypeObjs = $(".goodsType");            var goodsObjs = $(".goods");            var jsonParam = {"gm.goodsType.supplier.uuid": $("#supplier").val()};            var hasUuids = "";            for (i = 0; i < goodsTypeObjs.length; i++) {                hasUuids = hasUuids + $(goodsTypeObjs[i]).val();                hasUuids = hasUuids + ":";                hasUuids = hasUuids + $(goodsObjs[i]).val();                if (i != goodsTypeObjs.length - 1) {                    hasUuids = hasUuids + ",";                }            }            jsonParam["hasUuids"] = hasUuids;            //动态添加一个tr行            //创建tr组件            var $tr = $("<tr></tr>");            //创建td组件,生成商品类别select            var typeSelectStr = "<select class='goodsType' style='width:200px'>";            for (i = 0; i < 4; i++) {                typeSelectStr += "<option value='";                typeSelectStr += 111;                typeSelectStr += "'>";                typeSelectStr += "类别名称" + i;                typeSelectStr += "</option>";            }            typeSelectStr += "</select>";            var $td1 = $("<td height='30'>" + typeSelectStr + "</td>");            $tr.append($td1);            //创建td组件,生成商品select            var goodsSelectStr = "<select name='gmUuids' class='goods' style='width:200px'>";            for (i = 0; i < 4; i++) {                goodsSelectStr += "<option value='";                goodsSelectStr += 123;                goodsSelectStr += "'>";                goodsSelectStr += "新商品名" + i;                goodsSelectStr += "</option>";            }            goodsSelectStr += "</select>";            var $td2 = $("<td>" + goodsSelectStr + "</td>");            $tr.append($td2);            //创建td组件,生成商品数量input,默认值1            var $td3 = $("<td>&nbsp;<input name='nums' type='text' value='1' class='num order_num' style='width:67px;border:1px solid black;text-align:right;padding:2px' /></td>");            $tr.append($td3);            var $td4 = $("<td style='padding-left:4px'><input name='prices' type='text' value='" + 222 + "' class='prices order_num' style='width:93px;border:1px solid black;text-align:right;padding:2px' /> 元</td>");            $tr.append($td4);            var $td5 = $("<td class='total' align='right'>" + 222 + " 元</td>");            $tr.append($td5);            var $td6 = $("<td>&nbsp;&nbsp;<a class='deleteBtn delete xiu' value='" + 112 + "'><img src='../../../images/icon_04.gif'/> 删除</a></td>");            $tr.append($td6);            //在最后一个tr对象前添加该tr组件            $("#finalTr").before($tr);            //注意:新添加的元素是否具有动态事件激活能力            //获取后台数据是否还有下一个可用的商品,判断添加按钮是否显示            if ("Y" == "N") {                //将添加按钮设置为不可显示                $("#add").css("display", "none");            }            total();        });
       $("#add").click(function () {
           //设置不能修改供应商
           $("#supplier").attr("disabled", "disabled");
           //设置已存在的所有select全部不可点击
           $(".goodsType").attr("disabled", "disabled");
           $(".goods").attr("disabled", "disabled");

           //发送ajax提交,将供应商id与当前已经使用的类别对应商品2个id传递到后台,并将其过滤,过滤完毕的数据传递回页面
           var goodsTypeObjs = $(".goodsType");
           var goodsObjs = $(".goods");
           var jsonParam = {"gm.goodsType.supplier.uuid": $("#supplier").val()};
           var hasUuids = "";
           for (i = 0; i < goodsTypeObjs.length; i++) {
               hasUuids = hasUuids + $(goodsTypeObjs[i]).val();
               hasUuids = hasUuids + ":";
               hasUuids = hasUuids + $(goodsObjs[i]).val();
               if (i != goodsTypeObjs.length - 1) {
                   hasUuids = hasUuids + ",";
               }
           }
           jsonParam["hasUuids"] = hasUuids;

           //动态添加一个tr行
           //创建tr组件
           var $tr = $("<tr></tr>");

           //创建td组件,生成商品类别select
           var typeSelectStr = "<select class='goodsType' style='width:200px'>";
           for (i = 0; i < 4; i++) {
               typeSelectStr += "<option value='";
               typeSelectStr += 111;
               typeSelectStr += "'>";
               typeSelectStr += "类别名称" + i;
               typeSelectStr += "</option>";
           }
           typeSelectStr += "</select>";
           var $td1 = $("<td height='30'>" + typeSelectStr + "</td>");
           $tr.append($td1);

           //创建td组件,生成商品select
           var goodsSelectStr = "<select name='gmUuids' class='goods' style='width:200px'>";
           for (i = 0; i < 4; i++) {
               goodsSelectStr += "<option value='";
               goodsSelectStr += 123;
               goodsSelectStr += "'>";
               goodsSelectStr += "新商品名" + i;
               goodsSelectStr += "</option>";
           }
           goodsSelectStr += "</select>";
           var $td2 = $("<td>" + goodsSelectStr + "</td>");
           $tr.append($td2);

           //创建td组件,生成商品数量input,默认值1
           var $td3 = $("<td>&nbsp;<input name='nums' type='text' value='1' class='num order_num' style='width:67px;border:1px solid black;text-align:right;padding:2px' /></td>");
           $tr.append($td3);

           var $td4 = $("<td style='padding-left:4px'><input name='prices' type='text' value='" + 222 + "' class='prices order_num' style='width:93px;border:1px solid black;text-align:right;padding:2px' /> 元</td>");
           $tr.append($td4);

           var $td5 = $("<td class='total' align='right'>" + 222 + " 元</td>");
           $tr.append($td5);

           var $td6 = $("<td>&nbsp;&nbsp;<a class='deleteBtn delete xiu' value='" + 112 + "'><img src='../../../images/icon_04.gif'/> 删除</a></td>");
           $tr.append($td6);

           //在最后一个tr对象前添加该tr组件
           $("#finalTr").before($tr);
           //注意:新添加的元素是否具有动态事件激活能力

           //获取后台数据是否还有下一个可用的商品,判断添加按钮是否显示
           if ("Y" == "N") {
               //将添加按钮设置为不可显示
               $("#add").css("display", "none");
           }
           total();
       });
640?wx_fmt=png

可以使用两种方式来进行控制数据:

SQL控制:

//获取商品类别信息,类别必须有商品,企业ID=1,过滤掉1,2商品select distinct    gt.*from    tbl_goodsType gt,    tbl_goods gwhere    gt.supplierUuid = 1and    g.goodsTypeUuid = gt.uuidand    g.uuid not in (1,2,3,4,5)//过滤使用过的商品,2号类别,过滤掉1,2,3,4商品select    *from     tbl_goodswhere    goodsTypeUuid = 2and    uuid  not in (1,2,3,4)
select distinct
   gt.*
from
   tbl_goodsType gt,
   tbl_goods g
where
   gt.supplierUuid = 1
and
   g.goodsTypeUuid = gt.uuid
and
   g.uuid not in (1,2,3,4,5)

//过滤使用过的商品,2号类别,过滤掉1,2,3,4商品
select
   *
from
   tbl_goods
where
   goodsTypeUuid = 2
and
   uuid  not in (1,2,3,4)

程序控制:

    //已经使用过的,需要过滤的商品uuid    public String used;         //'11','22','33','44',    //ajax根据供应商的uuid获取类别和商品信息(具有数据过滤功能)    public String ajaxGetGtmAndGm2(){        gtmList = goodsTypeEbi.getAllUnionBySm(supplierUuid);        //由于类别数据中第一个类别的所有商品已经使用完毕,而没有将其删除,导致该商品类别对应的商品集合在下面的迭代过程中没有商品,抛出索引越界异常        //解决方案:删除掉对应的商品类别即可        //过滤掉所有商品已经使用完毕的商品类别        Goods:        for(int i = gtmList.size()-1 ;i>=0;i--){            List<GoodsModel> gmListTemp = goodsEbi.getAllByGtm(gtmList.get(i).getUuid());            for(GoodsModel gmTemp : gmListTemp){                if(!used.contains("'"+gmTemp.getUuid()+"'")){                    //保留该类别,直接判断下一个类别                    continue Goods;                }            }            //循环执行完毕,执行到的此处,上述循环没有进入if语句,里面的商品都使用过            gtmList.remove(i);        }        //上述集合中的类别一定都存在没有使用过的商品        gmList = goodsEbi.getAllByGtm(gtmList.get(0).getUuid());        //当前获取的商品信息的uuid具有重复的,要对其进行过滤        //对集合进行迭代删除,怎么做?必须逆向进行        //从gmList中取出所有的元素,挨个迭代,与本次传递过来的used进行比对,比对完发现重复的,删除掉(逆序进行)        for(int i = gmList.size()-1 ;i >=0 ;i--){            Long uuid = gmList.get(i).getUuid();            //判断该uuid是否出现在used中            if(used.contains("'"+uuid+"'")){                gmList.remove(i);            }        }        gm = gmList.get(0);        return "ajaxGetGtmAndGm";    }    //ajax根据商品类别uuid获取商品信息    public String ajaxGetGm(){        gmList = goodsEbi.getAllByGtm(gtmUuid);        //过滤数据        for(int i = gmList.size()-1 ;i >=0 ;i--){            Long uuid = gmList.get(i).getUuid();            //判断该uuid是否出现在used中            if(used.contains("'"+uuid+"'")){                gmList.remove(i);            }        }        gm = gmList.get(0);        return "ajaxGetGm";    }
   public String used;         //'11','22','33','44',
   //ajax根据供应商的uuid获取类别和商品信息(具有数据过滤功能)
   public String ajaxGetGtmAndGm2(){
       gtmList = goodsTypeEbi.getAllUnionBySm(supplierUuid);

       //由于类别数据中第一个类别的所有商品已经使用完毕,而没有将其删除,导致该商品类别对应的商品集合在下面的迭代过程中没有商品,抛出索引越界异常
       //解决方案:删除掉对应的商品类别即可
       //过滤掉所有商品已经使用完毕的商品类别
       Goods:
       for(int i = gtmList.size()-1 ;i>=0;i--){
           List<GoodsModel> gmListTemp = goodsEbi.getAllByGtm(gtmList.get(i).getUuid());
           for(GoodsModel gmTemp : gmListTemp){
               if(!used.contains("'"+gmTemp.getUuid()+"'")){
                   //保留该类别,直接判断下一个类别
                   continue Goods;
               }
           }
           //循环执行完毕,执行到的此处,上述循环没有进入if语句,里面的商品都使用过
           gtmList.remove(i);
       }
       //上述集合中的类别一定都存在没有使用过的商品

       gmList = goodsEbi.getAllByGtm(gtmList.get(0).getUuid());
       //当前获取的商品信息的uuid具有重复的,要对其进行过滤
       //对集合进行迭代删除,怎么做?必须逆向进行
       //从gmList中取出所有的元素,挨个迭代,与本次传递过来的used进行比对,比对完发现重复的,删除掉(逆序进行)
       for(int i = gmList.size()-1 ;i >=0 ;i--){
           Long uuid = gmList.get(i).getUuid();
           //判断该uuid是否出现在used中
           if(used.contains("'"+uuid+"'")){
               gmList.remove(i);
           }
       }
       gm = gmList.get(0);
       return "ajaxGetGtmAndGm";
   }

   //ajax根据商品类别uuid获取商品信息
   public String ajaxGetGm(){
       gmList = goodsEbi.getAllByGtm(gtmUuid);
       //过滤数据
       for(int i = gmList.size()-1 ;i >=0 ;i--){
           Long uuid = gmList.get(i).getUuid();
           //判断该uuid是否出现在used中
           if(used.contains("'"+uuid+"'")){
               gmList.remove(i);
           }
       }
       gm = gmList.get(0);
       return "ajaxGetGm";
   }

Juqery未来对象

如果在生成的代码不是当前对象的,那么绑定的事件就无法被激活了。因此需要使用live去激活未来对象。

640?wx_fmt=png
640?wx_fmt=png

2018年3月11日18:01:31更新!

Jquery高版本已经舍弃这个方法了,改成了on方法

订单设计

我们的订单可能分很多种:采购订单、销售订单、采购退货单、销售退货单

一般地,我们都不会将它们四种都用字段来表示出来,仅仅使用订订单状态字段进行了区分

如果文章有错的地方欢迎指正,大家互相交流。习惯在微信看技术文章,想要获取更多的Java资源的同学,可以关注微信公众号:Java3y


项目启动速度的本质:从模糊承诺到可验证的确定性 项目启动速度并非单纯追求时间最短,而是指在需求、环境、权限、依赖等关键要素就绪前提下,实现可量化、可验证、可追溯的首次交付能力。其底层逻辑是工程确定性管理——通过前置冻结需求、显性化依赖、最小权限授权和自动化就绪检查,将模糊的‘快’转化为T+X天级精度承诺。该能力直接决定客户信任建立效率与后续交付节奏稳定性,在软件交付、系统集成、AI平台落地等场景中尤为关键。本文聚焦启动阶段四大非技术制约因子及其破局实践,提供一套经27个项目验证的启动就绪方法论。 阅读详情

相关推荐

个人及家乡信息展示管理平台完整开发包

本文还有配套的精品资源,点击获取 简介:本压缩包提供了一个个人及家乡信息展示管理平台的完整开发资源,包括源码、视频教程和SQL数据库文件。该平台基于SSH框架构建,用于用户个人信息展示及家乡文化的分享。源码涵盖了后端逻辑、控制层和数据库操作。视频教程指导如何部署和定制平台,而SQL文件则用于搭建数据库环境。 1. 个人及家乡信息展示管理平台概述 1.1 平台...

weixin_42160645的博客 2167

ERP项目介绍——适合刚学完SSH的朋友

前言ERP项目是我学完SSH框架后做的第二个项目练习,第一个是前面介绍的JYUOA,这个项目的业务逻辑要比JYUOA复杂一下,但是在技术方面有很多使用的是类似的,像什么增删改查功能,还有公共功能抽取什么的。但是也有一些差别,你可以发现完成同一件事情会有不同的方法,通过两个项目的对比,你会觉得有些方法会比较好(没有比较就没有伤害~)。比如说在JYUOA中,是采用注解方式扫描bean和注入依赖,而ERP

腹黑大壁花 1万+

erpSSH2整合项目

该项目集struts2,hibernate,spring三大框架于一身,使用mvc结构,作为ssh2整合实例非常适合想学习做ssh2整合的人

JAVA ERP进销存管理系统 java+SSH+Ext架构

企业进销存系统,商品管理系统,系统功能完整,无BUG,界面洁简美观. 开发技术:java + SSH+Ext 版本:Struct2.0 、Spring 2.5 、Hibernate3 、Ext js 3.3 数据库: mySql 卖家推荐:商品进销存业务功能完整,代码结构分层清晰,易于做扩展二次开发。 本系统经百应软件工作室开发调试,持续出品更新补丁,已有数十位买家购

skybehind 1万+

【百度网盘】SSH企业案例erp_项目整合-完整高清视频+源码

【百度网盘】SSH企业案例erp_项目整合-完整高清视频+源码

sap销售发货的流程_SAP销售订单发货后如何实现发票的自动创建?

问SAP销售订单发货后如何实现发票的自动创建?答业务场景有些快消零售企业,SAP系统单据量大,单据金额少,一般在销售发货后即可确认收入。此时无需人工在系统内操作VF01或者VF04进行开票操作,可将该操作设置成后台作业进行自动批量开票,具体操作如下:1、定义任务:VF06输入完以上信息,点击保存进入以下界面:说明:当前日期的意思是“开票的日期”等于“系统电脑中的当前日期”当前日期+/-...

weixin_42358409的博客 3378

基于SSH框架的大型ERP系统

该项目文档、源码地址:https://github.com/ggb2312/Erp 该系统的权限部分已单独提取出来 https://www.jianshu.com/p/43b007b2973e 1. 项目简介 针对于中小型商贸企业的资源管理系统,是企业内部使用的综合信息管理服务平台。企业数据以WEB形式采集录入系统,经过收集汇总后,为各级终端用户提供日常业务信息管理、业务流程执行等日常办公服务...

weixin_34176694的博客 446

sentinel——SLC数据下载、DEM数据下载拼接、精密轨道数据下载方法

Sentinel——SLC数据下载、DEM数据下载、精密轨道数据下载方法 SLC数据下载 网址:https://search.asf.alaska.edu DEM数据下载 1 手动下载 http://srtm.csi.cgiar.org/srtmdata/ 3.在SARscape中使用下载好的DEM 将下载好的DEM放在软件默认下载DEM路径下(默认路径是C:\Users<用户名&g...

u011322358的博客 2万+

阅读SSH的ERP项目【第一篇】

tags: SSH整合与阅读项目 删除数据 实际业务中真正意义上的数据删除操作比较少见,多数情况是在数据中设置标记,通过标记的值来区分该数据是否可以用,而不是将数据真正的删除。 根据业务需求,为数据添加标记位,同时对数据的维护中添加启用/停用切换按钮,用于替换删除业务。所有的查询操作默认携带条件值为标记为可以的数据。除特殊业务外,标记为不可用的数据将不参与日常数据操作。 javaScript数...

weixin_34279061的博客 137

SO逆向入门实战教程一:OASIS

文章目录一、前言二、准备三、Unidbg模拟执行四、ExAndroidNativeEmu 模拟执行五、算法分析六、尾声 一、前言 这是SO逆向入门实战教程的第一篇,总共会有十三篇,十三个实战。有以下几个注意点: 主打入门级的实战,适合有一定基础但缺少实战的朋友(了解JNI,也上过一些Native层逆向的课,但感觉实战匮乏,想要壮壮胆,入入门)。 侧重新工具、新思路、新方法的使用,算法分析的常见路子是Frida Hook + IDA ,在本系列中,会淡化Frida 的作用,采用Unidbg Hook + .

lilac的博客 2万+

【100%通过率】华为od机试C卷【出差 / 员工派遣】Java&Go 实现

某公司部门需要派遣员工去国外做项目。现在,代号为 x 的国家和代号为 y 的国家分别需要 cntx 名和 cnty 名员工部门每个员工有一个员工号 (1,2,3,......),工号连续,从 1开始。部长派遣员工的规则:

MISAYAONE的博客 2652

阅读SSH的ERP项目【第二篇】

tags: SSH整合与阅读项目 权限控制菜单树 每个菜单树需要的权限可能是不一样的,要想用权限系统去管理菜单树,就要把菜单树写成是动态的。 菜单模型设计如下: 菜单名称,菜单编号,所属父级菜单对象,菜单对应访问路径 在查询的时候用到了自关联 商品联动 在页面加载的时候,查询出**所有供应商的数据、查询第一个供应商商品的类别以及第一个商品类别对应的所有信息集合。**那么在页面上我们...

weixin_34313182的博客 120

软件可靠性设计

本文系统介绍了软件可靠性设计与建模的理论框架和实施方法。首先从可靠性定义、核心思想和与建模的关系等理论基础出发,重点阐述了模块化设计、冗余容错、异常处理等六类可靠性设计方法及其技术栈。文章详细分析了可靠性设计在软件生命周期各阶段的应用,并深入探讨了设计与建模的深度结合机制,包括参数影响、验证方法和量化指标。最后提出了覆盖设计、开发、测试和运行四个阶段的落地策略,形成完整的"设计-建模-运行"流程体系。全文强调通过预防性设计和量化建模相结合的方法提升软件系统的可靠性和稳定性。

moton2017的博客 901

用ComfyUI打造本地AIGC二创工作流:角色瞬间切换实战

AIGC(人工智能生成内容)正在重构短视频与数字内容的创作方式,而角色一致性、表情动作迁移、图生视频等技术是实现高质量二创效果的关键基础。实际应用中,云端会员制模板常存在成本高、灵活性差的局限,将ComfyUI部署在本地,以节点化工作流串联面部参考、姿态控制与关键帧切换,能构建出可复现、可批量调用、可对接API的内容生产链路。整套方案在短视频二创、虚拟角色短片、表情包批量生成等场景中极具实用价值,关键路径可归纳为ComfyUI本地部署、工作流串联与接口封装三阶段。

weixin_33965305的博客 338

Allegro174版本如何关闭模块复用后铜皮自动从动态变成静态操作指导

在用Allegro进行PCB设计的时候,模块复用是使用的十分频繁的操作,当Allegro升级到了174 S034版本的时候,当使用模块复用的功能的时候,模块内的铜皮会自动动静转换,大部分情况是不需要的。版本如何关闭模块复用后铜皮自动从动态变成静态操作指导。如何关闭这个功能,具体操作如下。

weixin_54787054的博客 1264

光学系统仿真软件:Finesse_(6).噪声分析与优化

在Finesse中,噪声源的定义可以通过在光学元件的参数中添加噪声项来实现。以下是一个简单的示例,展示了如何在激光器和反射镜中定义噪声源。# 定义噪声传递函数# 绘制噪声传递函数plot NTF1在这个例子中,定义了一个噪声传递函数NTF1,描述了激光器L1到反射镜M1的噪声传递过程。plot NTF1命令绘制了噪声传递函数的频谱图。# 定义耦合路径# 绘制耦合噪声频谱图plot C1在这个例子中,定义了一个耦合路径C1,描述了激光器L1和反射镜M1之间的噪声耦合关系。plot C1。

kkchenjj的博客 875

Day77 Java框架 SSH案例_ERP(十一)_CXF框架_红日物流BOS系统_ERP物流信息管理

WebService与CXF简介 一.WebService WebService是一种跨编程语言和跨操作系统平台的远程调用技术。 跨编程语言和跨操作平台 : 就是说服务端程序采用java编写,客户端程序则可以采用其他编程语言编写,反之亦然!跨操作系统平台则是指服务端程序和客户端程序可以在不同的操作系统上运行。 远程调用 : 就是一台计算机a上的一个程序可以调用到另外一台计算机b上...

ambition 385

人工智能混合编程实践:C++调用封装好的DLL进行异常检测推理

C++、Python、ONNX、人工智能、异常检测、Anomalib 2.1.0

FriendshipTang的博客 174

SSH免密登录:原理、配置与自动化运维实战指南

SSH(Secure Shell)是一种广泛用于远程登录和管理服务器的加密网络协议,其核心价值在于提供安全的远程访问和数据传输。其工作原理基于非对称加密技术,通过公钥和私钥对实现身份验证,相比传统的密码认证,具备更强的抗暴力破解能力和更高的安全性。这项技术的核心价值在于实现服务器间的安全互信,为自动化运维和持续集成/持续部署(CI/CD)流程奠定基础。在实际应用场景中,SSH免密登录是自动化脚本执行、批量服务器管理、集群节点通信以及CI/CD流水线中自动部署的关键支撑。本文聚焦于SSH免密登录的配置,深入解

weixin_30439067的博客 419

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

本科毕业论文:基于B/S的ERP人力资源管理子系统的设计与开发

本科毕业论文:基于B/S的ERP人力资源管理子系统的设计与开发 【下载地址】本科毕业论文基于BS的ERP人力资源管理子系统的设计与开发 本项目是一个基于B/S架构的ERP人力资源管理子系统的设计与开发实践,专为现代企业高效管理人力资源而设计。通过整合Struts、Spring和Hibernate三大主流框架,系统实现了部...

gitblog_06778的博客 380

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

轮胎行业EDI:Tigar 轮胎EDI项目案例

Tigar 轮胎是一家塞尔维亚轮胎制造公司,自2007年开始,被轮胎制造商米其林持有。Tigar通过EDI来传输与供应商之间的业务单据,优化业务流程。本文将从EDI需求概览、如何基于知行之桥EDI系统实现与Tigar的EDI对接以及项目回顾这三个部分为大家展开介绍。

EDI电子数据交换 | 知行软件 1250

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

java一

第 1 章 软件设计与环境搭建 一、ERP 简介 (一)什么是 ERP ERP 系统是企业资源计划(Enterprise Resource Planning )的简称,是指建立在信息技术基础上,以系统化的管理思想,为企业决策层及员工提供决策运行手段的管理平台。ERP 系统集信息技术与先进管理思想于一身,成为现代企业的运行模式,反映时代对企业合理调配资源,最大化地创造社会财富的要求

baoliantu的博客 648

JAVA实习生刚刚入职,公司会让你做什么?

作为一个已经参加5年开发的程序员告诉你 首先去了解你所在的项目组都有那些项目,尽可能快的熟悉项目,都看代码。 另外,多和公司的技术大牛门沟通。 有问题一定要不厌其烦的去问,一定要弄懂个根源。 开发中,只要是错误就能找到根源,所以,自己一旦遇上了问题,就一定要弄出个所以然来,以后你永远都不会忘记。 另外,业余时间一定要学习…这个是你在工作之余,提高自己能力的最重要的途径。 好了,安心的实习吧,java没你想那么难。 首先去了解你所在的项目组都有那些项目,尽可能快的熟悉项目,都看代码。 另外,多和公司的技术大

m0_46632354的博客 8873

国内首部基于JBPM5.4实战流程引擎开发(动态表单、模板引擎、公文管理系统)

一、课程来源:          该课程是基于贝斯ERP系统中的一个流程管理模块,基于java及JBPM5.4流程引擎技术开发.鉴于JBPM5.4版本较新,而目前网上基本上没有对应的简单实例,更不要说负责案例及项目设计,所以北风网推出该系列教程结合多个实例的公文管理系统,并配合动态表单设计让学员事半功倍。           本课程是在国内没有任何中文文档的情况下,完全靠翻译国外的英文文

u011851589的专栏 3773

java计算机毕业设计小说阅读网站源程序+mysql+系统+lw文档+远程调试

java计算机毕业设计小说阅读网站源程序+mysql+系统+lw文档+远程调试。springboot基于Springboot的大学宿舍管理系统。springboot基于SpringBoot的电影社区网站。springboot区域医疗服务监管可视化系统。jspjava学习平台精品课程mysqlssh。springboot奥利给共享自习室系统。springboot精品在线试题库系统。

bishe405的博客 174

基于JAVA大学生能力建设项目管理系统计算机毕业设计源码+系统+lw文档+部署

springboot基于springboot框架的企业合同管理系统设计与实现。JSP基于JSP的美容服务预约系统的设计与实现sqlserver。jspmysql医院体检中心个人健康状况信息管理系。ssm基于Java的幼儿早教系统软件的设计与实现。ssm基于SSM的停车场收费管理系统的设计与实现。ssm基于Java的台球收费管理系统的设计与实现。ssm基于web的家教信息服务平台的设计与实现。ssm基于Java的高校教学资源库的设计与实现。ssm校园流浪猫图鉴管理系统的设计与实现。

bishe606的博客 445
上一篇: 阅读SSM项目之scm
下一篇: Spring【AOP模块】就是这么简单
Java3y
Java3y 领域专家: 后端开发技术领域 领域专家: 后端开发技术领域
博客等级 码龄9年 1万+粉丝 509原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值