




已阅读5页,还剩79页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
CRM_01l 集成spring和hibernate,拷贝jar文件n 拷贝相应的jar文件到/WEB-INF/lib目录下u MySql的mysql-connector-java-3.1.13-bin.jaru Spring的dist目录下的spring.jar文件u Spring的libaspectj目录下的两个jar文件u Hibernate的hibernate3.jar文件u Hibernate的lib目录下的所有jar文件n 拷贝相应的配置文件到/WEB-INF目录下u web.xmln 拷贝相应的配置文件到/src目录下u Spring的配置文件applicationContext-*.xmlu Hibernate的配置文件hibernate.cfg.xmlu 日志文件pertiesu 国际化资源文件MessageRpertiesl 了解DAO接口与业务逻辑接口设计之间的差异l 了解利用hibernate进行标准对象查询的基本方法(请参考CustomerDAO的hibernate实现类)Customer.java客户实体类package com.axjy.crm.model;/* hibernate.class table=T_Customer * hibernate.discriminator column=customerCategory type=string /单表继承*/public class Customer private int id;private String name;private String shortName;/助记名称private String sn; /编号private String evaluation; /价值评估private String creditRating;/信用等级private String type;/客户类型private String industry;/行业类别private String relationRating;/关系等级private String source;/客户来源private String currentStatus;/客户阶段private Customer parent;/父客户private String country; /国家private String phone;/电话private String province; /省份private String fax;/传真private String city; /城市private String site;/网站private String postcode;/邮政编码private String address;/地址private String description; /备注private Date createTime; /创建时间private User owner;/所有者public String getAddress() return address;public void setAddress(String address) this.address = address;public String getCity() return city;public void setCity(String city) this.city = city;public String getCountry() return country;public void setCountry(String country) this.country = country;public Date getCreateTime() return createTime;public void setCreateTime(Date createTime) this.createTime = createTime;public String getCreditRating() return creditRating;public void setCreditRating(String creditRating) this.creditRating = creditRating;public String getCurrentStatus() return currentStatus;public void setCurrentStatus(String currentStatus) this.currentStatus = currentStatus;public String getDescription() return description;public void setDescription(String description) this.description = description;public String getEvaluation() return evaluation;public void setEvaluation(String evaluation) this.evaluation = evaluation;public String getFax() return fax;public void setFax(String fax) this.fax = fax;public int getId() return id;public void setId(int id) this.id = id;public String getIndustry() return industry;public void setIndustry(String industry) this.industry = industry;public String getName() return name;public void setName(String name) = name;public User getOwner() return owner;public void setOwner(User owner) this.owner = owner;public Customer getParent() return parent;public void setParent(Customer parent) this.parent = parent;public String getPhone() return phone;public void setPhone(String phone) this.phone = phone;public String getPostcode() return postcode;public void setPostcode(String postcode) this.postcode = postcode;public String getRelationRating() return relationRating;public void setRelationRating(String relationRating) this.relationRating = relationRating;public String getShortName() return shortName;public void setShortName(String shortName) this.shortName = shortName;public String getSite() return site;public void setSite(String site) this.site = site;public String getSn() return sn;public void setSn(String sn) this.sn = sn;public String getSource() return source;public void setSource(String source) this.source = source;public String getType() return type;public void setType(String type) this.type = type;public String getProvince() return province;public void setProvince(String province) vince = province;CompanyCustomer.java公司客户package com.axjy.crm.model;/* hibernate.subclass*/public class CompanyCustomer extends Customer /单表继承private String employeeSize;/人员规模public String getEmployeeSize() return employeeSize;public void setEmployeeSize(String employeeSize) this.employeeSize = employeeSize; PersonalCustomer.java个人客户package com.axjy.crm.model;/* hibernate.subclass */public class PersonalCustomer extends Customer /单表继承private String sex; /性别public String getSex() return sex;public void setSex(String sex) this.sex = sex;Customer.hbm.xml /指定区分客户类别的字段名称和类型 /公司客户时增加人员规模字段 /个人客户时增加性别字段ContactPerson.java联系人实体类package com.axjy.crm.model;public class ContactPerson private int id;private Customer customer; /客户private String name;/姓名private String sex;/性别private String grade; /重要等级private String responsibility;/负责业务private String term;/称谓private String type; /类型private String department; /部门private String duty;/职务private String officePhone;/办公电话private String fax;/传真private String cellPhone;/移动电话private String email;/电子邮件private String homePhone;/家庭电话private String msn;/msn/qqprivate String homeAddress; /家庭住址private Date birthday;/生日private String preference;/兴趣爱好private String description;/备注public Date getBirthday() return birthday;public void setBirthday(Date birthday) this.birthday = birthday;public String getCellPhone() return cellPhone;public void setCellPhone(String cellPhone) this.cellPhone = cellPhone;public Customer getCustomer() return customer;public void setCustomer(Customer customer) this.customer = customer;public String getDepartment() return department;public void setDepartment(String department) this.department = department;public String getDescription() return description;public void setDescription(String description) this.description = description;public String getDuty() return duty;public void setDuty(String duty) this.duty = duty;public String getEmail() return email;public void setEmail(String email) this.email = email;public String getFax() return fax;public void setFax(String fax) this.fax = fax;public String getGrade() return grade;public void setGrade(String grade) this.grade = grade;public String getHomeAddress() return homeAddress;public void setHomeAddress(String homeAddress) this.homeAddress = homeAddress;public String getHomePhone() return homePhone;public void setHomePhone(String homePhone) this.homePhone = homePhone;public int getId() return id;public void setId(int id) this.id = id;public String getMsn() return msn;public void setMsn(String msn) this.msn = msn;public String getName() return name;public void setName(String name) = name;public String getOfficePhone() return officePhone;public void setOfficePhone(String officePhone) this.officePhone = officePhone;public String getPreference() return preference;public void setPreference(String preference) this.preference = preference;public String getResponsibility() return responsibility;public void setResponsibility(String responsibility) this.responsibility = responsibility;public String getSex() return sex;public void setSex(String sex) this.sex = sex;public String getTerm() return term;public void setTerm(String term) this.term = term;public String getType() return type;public void setType(String type) this.type = type;ContactPerson.hbm.xml DataDictionary.java数据字典实体类package com.axjy.crm.model;public class DataDictionary private int id;private String category;/字典类别:比如性别、省份、国家等等private String code;/代码private String text;/文本public int getId() return id;public void setId(int id) this.id = id;public String getCategory() return category;public void setCategory(String category) this.category = category;public String getCode() return code;public void setCode(String code) this.code = code;public String getText() return text;public void setText(String text) this.text = text;DataDictionary.hbm.xml User.java用户实体类package com.axjy.crm.model;public class User private int id;private String username;private String password;public int getId() return id;public void setId(int id) this.id = id;public String getUsername() return username;public void setUsername(String username) this.username = username;public String getPassword() return password;public void setPassword(String password) this.password = password;User.hbm.xmlhibernate.cfg.xmljdbc:mysql://crmcom.mysql.jdbc.Driverrootaxjyorg.hibernate.dialect.MySQLDialecttrueupdateCustomerDAO.java专门针对数据库处理package com.axjy.crm.dao;public interface CustomerDAO public void save(Customer customer);public void update(Customer customer);public void del(Customer customer);public Customer findById(int id);public List findAll();public List findCustomers(Customer customer); /通过Customer传递查询条件是一种比较灵活的处理方法CustomerDAOImpl.javapackage com.axjy.crm.dao.impl.hibernate;public class CustomerDAOImpl extends HibernateDaoSupport implements CustomerDAO public List findCustomers(Customer customer) List list = null;/通过hibernateTemplate findByExample对象查询,这是一种精确查询/list = getHibernateTemplate().findByExample(customer);/标准对象查询,可以实现模糊查询/list = getSession().createCriteria(customer.getClass()/.add(Restrictions.like(address, %+customer.getAddress()+%).list();/使用Example对象进行查询list = getSession().createCriteria(customer.getClass().add(Example.create(customer).enableLike(MatchMode.ANYWHERE).excludeProperty(address) .list(); /在hibernate拼装查询条件的时不包括address属性/使用投影(projection)进行查询,返回结果是Integer类型,而不是Long类型Integer rowCount = (Integer)getSession().createCriteria(customer.getClass().setProjection(Projections.rowCount().add(Example.create(customer).enableLike(MatchMode.ANYWHERE).excludeProperty(address).uniqueResult();System.out.println(rowCount);return list;public void save(Customer customer) getHibernateTemplate().save(customer);public void update(Customer customer) getHibernateTemplate().update(customer);public void del(Customer customer) getHibernateTemplate().delete(customer);public Customer findById(int id) return (Customer)getHibernateTemplate().load(Customer.class, id);public List findAll() return getHibernateTemplate().find(from Customer);CustomerManager.java专门针对呈现层处理package com.axjy.crm.manager;public interface CustomerManager public void addCustomer(Customer customer,int parentId,int ownerId);public void updateCustomer(Customer customer,int parentId,int ownerId);public void delCustomer(int customerId);public Customer findCustomer(int customerId);public List searchAll();public List searchCustomers(Customer customer);CustomerManagerImpl.javapackage com.axjy.crm.manager.impl;public class CustomerManagerImpl implements CustomerManager private CustomerDAO customerDAO;public void setCustomerDAO(CustomerDAO customerDAO) this.customerDAO = customerDAO;public void addCustomer(Customer customer, int parentId, int ownerId) if(parentId != 0)customer.setParent(customerDAO.findById(parentId);/TODO 调用userDAO查询获得user对象customerDAO.save(customer);public void updateCustomer(Customer customer, int parentId, int ownerId) if(parentId != 0)customer.setParent(customerDAO.findById(parentId);/TODO 调用userDAO查询获得user对象customerDAO.update(customer);public void delCustomer(int customerId) customerDAO.del(customerDAO.findById(customerId);public Customer findCustomer(int customerId) return customerDAO.findById(customerId);public List searchAll() return customerDAO.findAll();public List searchCustomers(Customer customer) return customerDAO.findCustomers(customer);applicationContext-beans.xml/与数据库打交道需要注入sessionFactoryapplicationContext-common.xmlclasspath:hibernate.cfg.xml web.xml/注意本项目没有使用struts框架,不需要struts的相关配置contextConfigLocationclasspath*:applicationContext-*.xmlorg.springframework.web.context.ContextLoaderListenerCustomerManagerTest.javapackage com.axjy.crm.manager;public class CustomerManagerTest extends TestCase private static BeanFactory factory = new ClassPathXmlApplicationContext(applicationContext-*.xml);public void testAddCustomer() CustomerManager cm = (CustomerManager)factory.getBean(customerManager);for(int i=0; i 0.5 ? new CompanyCustomer() : new PersonalCustomer();customer.setAddress(address地址+i);customer.setCity(北京);customer.setName(客户+i);customer.setSn(customer +Math.random();cm.addCustomer(customer, 0, 0);/通过hibernateTemplate findByExample对象查询public void testSearchCustomers() CustomerManager cm = (CustomerManager)factory.getBean(customerManager);Customer customer = new Customer();customer.setId(18); /ID不参与查询条件的构建customer.setCity(北京);customer.setSn(customer);/通过hibernateTemplate findByExample对象查询是一种精确查询,除id外所有的赋过值属性都将参与精确查询/getHibernateTemplate().findByExample(cust
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025江苏无锡市妇联实验托幼中心招聘编外工作人员10人备考考试题库附答案解析
- 2026粤规科技校园招聘备考考试题库附答案解析
- 工厂安全培训活动的感想
- 资阳现代农业发展集团有限公司下属子公司一般员工市场化招聘(6人)备考考试题库附答案解析
- 工厂安全培训标语课件
- 线上线下数据联动-洞察及研究
- 2025重庆大学土木工程学院科研团队劳务派遣工勤人员招聘1人备考考试题库附答案解析
- 2025版男科疾病常见症状及护理技巧
- 运动饮食养成之道
- 发动机轻量化设计-第1篇-洞察及研究
- Kappa测试数据分析报告
- 安吉汽车物流运输优化方案全套
- 新教材-人教版高中物理选择性必修第一册 第一章 动量守恒定律 知识点考点重点难点提炼汇总
- 变更董事股东会决议
- 02jrc901b电子海图操作jan中文说明书
- 精选幼儿园体能大循环方案
- 全国中学生物理竞赛复赛实验考查
- 例谈小组合作学习在小学英语教学中的有效开展(讲座)课件
- 部编版五年级道德与法治上册第3课《主动拒绝烟酒与毒品》优秀课件【最新】
- 《认识分式》教学课件【初中数学】公开课
- 制造企业物料试用单
评论
0/150
提交评论