三大框架配置[注解模式版].doc_第1页
三大框架配置[注解模式版].doc_第2页
三大框架配置[注解模式版].doc_第3页
三大框架配置[注解模式版].doc_第4页
三大框架配置[注解模式版].doc_第5页
已阅读5页,还剩18页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

三大框架配置注解模式版1.新建web项目2.添加hibernate框架3.添加Spring框架4.添加Struts2框架Struts2 JAR包导入选中并复制所有JAR包粘贴到项目lib文件夹下重复操作将Struts2中Spring支持JAR包导入lib文件夹下复制粘贴到项目lib文件夹下5.将dbcp JAR包导入礼包文件夹下完成后所有JAR包添加成功6.hibernate.cfg.xml文件中的datasource,hbernateproperties,mappingresource/mappingclass均可在applicationContext.xml中添加。可将hibernate.cfg.xml文件删除后在applicationContext.xml中配置。在applicationContext.xml中修改头文件,改为如下:在applicationContext.xml中配置datasource,hbernateproperties,mappingresource/mappingclass将生成的LocalSessionFactoryBean修改为AnnotationSessionFactoryBean添加功能配置7.包的创建8.数据库反射创建dto,dao。生成的类中Student中属性的long类型修改为int,StudentDAO中的的log属性删除生成的StudentDAO和StudentDAOImpl,可根自身习惯将方法实体写入StudentDAOImpl,而接口类写入StudentDAO。在此只需更改类名,互换包的位置即可9.Service类,Service接口类,Action类StudentServices类:package com.hrs.services;import java.util.List;import org.hibernate.SessionFactory;import org.springframework.beans.factory.annotation.Autowired;import com.hrs.model.Student;public interface Studentservice void save(Student transientInstance);void delete(Student persistentInstance);Student findById(java.lang.Long id);List findAll();Student merge(Student detachedInstance);StudentServiceImpl类package com.hrs.services.impl;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import org.springframework.transaction.annotation.Propagation;import org.springframework.transaction.annotation.Transactional;import com.hrs.dao.Studentdao;import com.hrs.model.Student;import com.hrs.services.Studentservice;Service(studentservice)Transactional(propagation=Propagation.REQUIRED)public class StudentserviceImpl implements Studentservice private Studentdao studentdao;public void save(Student transientInstance) System.out.println(我是数据服务层);studentdao.save(transientInstance);public void delete(Student persistentInstance) studentdao.delete(persistentInstance);public Student findById(Long id) return studentdao.findById(id);public List findAll() return studentdao.findAll();public Student merge(Student detachedInstance) return studentdao.merge(detachedInstance);Autowiredpublic void setStudentdao(Studentdao studentdao) this.studentdao = studentdao;StudentAction类package com.hrs.actions;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import com.hrs.model.Student;import com.hrs.services.Studentservice;import com.opensymphony.xwork2.ActionSupport;Controller(studentAction)public class StudentAction extends ActionSupport private Student stu;private Studentservice service;Autowiredpublic void setService(Studentservice service) this.service = service;public Student getStu() return stu;public void setStu(Student stu) this.stu = stu;public String save() System.out.println(stu);System.out.println(我是业务逻辑层);service.save(stu); return this.SUCCESS;ApplicationContext.xml文件org.hibernate.dialect.Oracle9Dialectupdatetrue com.hrs.model.Student Struts2.xml文件/index.jsp 10.web.xml配置 index.jsp encodingorg.springframework.web.filter.CharacterEncodingFilterencodingUTF-8encoding/*contextConfigLocationclasspath:applicationContext.xmlorg.springframework.web.context.ContextLoaderListenerOpenSessionInViewFilterorg.springfram

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论