兰州工业学院毕业设计说明书(论文)
name=\ name=\ 在web.xml中对struts2的注入代码如下: xmlns=\ xmlns:xsi=\ xsi:schemaLocation=\ http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd\ org.apache.struts2.dispatcher.FilterDispatcher 24 兰州工业学院毕业设计说明书(论文) 4.6.4持久层设计 由实体类和数据访问对象(dao)充当。 数据的底层存储是数据库,每张表都有一个对应的实体类,用于数据的持久化操作。每张表都提供一个数据访问对象(dao),用于对数据库的数据进行连接操作。Dao对象的创建,我们采用了工厂模式。 所有的实体类都实现了序列化接口。下面展示部门信息的相关业务实现的相关代码,一个bmxx表的对应实现类Bmxx,一个对应的dao类BmxxDao,一个创建DAO对象的工厂类。代码示例: package com.insigma.work.bmxx.model; /** * Bmxx entity. @author MyEclipse Persistence Tools * Bmxx 表的实体类及javaBean */ public class Bmxx implements java.io.Serializable { // Fields private String bmbh; private String bmmc; private String sjbh; // Constructors /** default constructor */ public Bmxx() { } /** full constructor */ public Bmxx(String bmbh, String bmmc, String sjbh) { this.bmbh = bmbh; this.bmmc = bmmc; this.sjbh = sjbh; } // Property accessors public String getBmbh() { return this.bmbh; } public void setBmbh(String bmbh) { this.bmbh = bmbh; } public String getBmmc() { return this.bmmc; } public void setBmmc(String bmmc) { this.bmmc = bmmc; } public String getSjbh() { return this.sjbh; 25 兰州工业学院毕业设计说明书(论文) } } public void setSjbh(String sjbh) { this.sjbh = sjbh; } public void setMobile(String mobile) { this.mobile = mobile; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } Dao层接口: public interface BmxxDao { public void insert(Bmxx bmxx); public void update(Bmxx bmxx); public void delete(Bmxx bmxx); public Bmxx getExampleById(String bmbh); public List getBmxxList(String sql); public Page getBmxxPageList(int pageNumber,String sql); } Dao 层接口的实现类BmxxDaoImpl: public class BmxxDaoImpl extends HibernateDaoSupport implements BmxxDao { /** * dao层接口的实现类,主要实现增、删、改、查等功能! * java分页技术的实现 * 所有记录数的查询 */ @Override public void insert(Bmxx bmxx) { this.getHibernateTemplate().getSessionFactory().getCurrentSession().save(bmxx); System.out.println(\插入成功了\ } public void update(Bmxx bmxx) { this.getHibernateTemplate().getSessionFactory().getCurrentSession().update(bmxx); System.out.println(\修改成功了\ } public void delete(Bmxx bmxx) { this.getHibernateTemplate().getSessionFactory().getCurrentSession().delete(bmxx); 26 兰州工业学院毕业设计说明书(论文) System.out.println(\删除成功了\ } public List getBmxxList(String hql) { System.out.println(\查询成功了\ Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery(hql); return query.list(); } public Bmxx getExampleById(String bmbh) { return (Bmxx)this.getHibernateTemplate().getSessionFactory().getCurrentSession().get(Bmxx.class, bmbh); } public Page getBmxxPageList(int pageNumber, String sql) { int startCount = (pageNumber - 1) * PageSize.pageSize; int count = getCount(sql); String queryString = \ Query queryObject = getSession().createQuery(queryString); queryObject.setFirstResult(startCount); queryObject.setMaxResults(PageSize.pageSize); List list = queryObject.list(); Page page = new Page(list, count, pageNumber); return page; } /** * 查询所有记录数 */ private int getCount(String sql){ Query queryObject = getSession().createQuery(\Bmxx where 1=1\ List list=queryObject.list(); return list.size(); } } 4.6.5工具类设计 工具类提供静态方法,与业务无关而可以单独使用的,用于供业务类调用。这里提供的工具类方法有:随机生成指定位数的客户端编号方法,用于客户端编号;文件判断类方法,用于判断上传的文件是否存在,是否你为空等。 文件判断类方法代码示例: public class FileUpload { public static boolean uploadFile(String path, File file, String fileName) { boolean boo = false; 27 兰州工业学院毕业设计说明书(论文) } } //判断文件是否为空 if (file != null) { //就在该文件夹下面,生成一个fileName为文件 File savefile = new File(new File(path), fileName); //用这个文件到该文件夹下面,判断该文件是否存在 if (!savefile.getParentFile().exists()) //新建一个文件 savefile.getParentFile().mkdirs(); try { //将文件内容拷到新建的这个文件里面 FileUtils.copyFile(file, savefile); boo = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return boo; 4.6.6 Sping配置文件 Sping配置文件和hibernate配置文件部分代码如下: xmlns:aop=\ xmlns:tx=\ xsi:schemaLocation=\http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd\ value=\ 28 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库人力资源管理(毕业论文)(7)在线全文阅读。
相关推荐: