SSH配置过程(菜鸟级别)_第1页
SSH配置过程(菜鸟级别)_第2页
SSH配置过程(菜鸟级别)_第3页
SSH配置过程(菜鸟级别)_第4页
SSH配置过程(菜鸟级别)_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

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

文档简介

1 先将 log4j properties 这个日志文件放在 src 目录下 这个日志文件表示输出工程的日志 2 讲 struts xml 文件放到 src 目录下 3 在 webRoot 目录的 web xml 文件下配置 Struts 过滤器 index jsp contextConfigLocation WEB INF spring xml struts2CleanUpFilter org apache struts2 dispatcher ActionContextCleanUp struts2Filter org apache struts2 dispatcher ng filter StrutsPrepareAndExecut eFilter hibernateOpenSessionInViewFilter org springframework orm hibernate3 support OpenSessionInViewFi lter hibernateOpenSessionInViewFilter action struts2CleanUpFilter action struts2Filter org springframework web context ContextLoaderListener org springframework web util IntrospectorCleanupListener 注 不是每个都必须配置 web app 中的配置顺序必须按照下面的顺序配置 不然可能会报错 icon display name description distributable context param filter filter mapping listener servlet servlet mapping session config mime mapping welcome file list error page taglib resource env ref resource ref security constraint login config security role env entry ejb ref ejb local ref 4 在web INF目录下创建 spring dao xml spring base xml spring action xml spring service xml 注 新建过程 NEW Basic Templats 注 spring action 管理strutsaction spring service xml 对应service接口 spring dao xml 对应dao接口 spring base xml 数据库的连接以及基本连接 在上面4个xml文件中 每一个都添加头文件 5 添加架包 6 以上搭建完成后将工程发布到Tomcat上 测试下看看有没有错 7 在spring base xml下面配置相关的数据库的访问信息 1 数据源 2 使用连接池连接数据库 c3p0连接数据库 3 配置实体类和hbm xml文件的映射关系 4 配置格式化sql 方言 配置是否输出sql等 5 配置事务 使用spring的aop的声明式事务 8 在spring base xml中继续配置数据源 参考c3p0的配置文件 注 root以及admin和mydata分别是自己的数据库用户名 数据库密码 数据库名称 maxPoolSize和minPoolSize分别是最大连接数和最小连接数 maxStatements是最大 连接空间 9 在spring base xml中继续配置sessionFactory 注 dataSource是LocalSessionFactoryBean类中的一个属性 表示sessionFactory需要的数据 源由上面配置的C3P0提供 和C3P0配置的id相统一 org hibernate dialect MySQLDialect true true 注 hibernate dialect hibernate show sql hibernate format sql 分别 表示方言 输出sql语句 sql语句格式 10 需要加载映射文件 有两种方式 第一种是xml 第二种是class类 注解jpa 下面使用xml Value里面的设置比如 com diandou user user hbm xml List中有一个配置文件value就有几个 注 映射属性文件 11 可以再次发布到Tomcat上 用来测试程序是否有错 12 在src目录下新建 NEW XML Advanced Templates 可加可不加 Hibernate cfg xml admin root jdbc mysql mydata org hibernate dialect MySQLDialect admin com mysql jdbc Driver true true create drop 13 在src目录下创建包和类 用来创建数据库的工具栏Hbm2ddl java package mon hibernatetools import org hibernate cfg Configuration import org hibernate tool hbm2ddl SchemaExport public class Hbm2ddl public Hbm2ddl TODO Auto generated constructor stub public static void main String args TODO Auto generated method stub Configuration config new Configuration configure SchemaExport export new SchemaExport config export create true true export setDelimiter export setFormat true 14 在src下添加domain 实体类 需要加包 实体类中要有构造方法和get set方法 15 在domain相同的包下面建 实体类名 hbm xml文件 上面这个是用来配置实体类映射hibernate hbm xml的头文件 必须带 下面是一个例子 16 在index jsp中创建form表单 String path request getContextPath 只留这一个 添加一个 pageEncoding utf 8 这个注意要修改 注意action的名称写法 要和struts xml中的相对应 17 在spring base xml文件中添加实体类的映射文件 添加这行 com diandou domain Myemployee hbm xml 18 添加action类 注意 action类在创建的时候要 Superclass com opensymphony xwork2 ActionSupport 并且Interfaces ModelDriven 不带T 类中要写 例子 注意getModel方法和 变量的set get方法 public class EmployeeAction extends ActionSupport implements ModelDriven private Myemployee myemployee public Myemployee getMyemployee return myemployee public void setMyemployee Myemployee myemployee this myemployee myemployee public EmployeeAction TODO Auto generated constructor stub public Object getModel TODO Auto generated method stub if myemployee null myemployee new Myemployee return myemployee 19 在action类中添加完方法后要配置struts xml文件中的 success jsp 20 在Action中添加方法 要注入service接口 set和get方法 注入实体类 Employee employee set和get方法 在EmployeeServiceImp中要注入EmployeeDao employeeDao set和get方法 在add方法中写上getDao add employee service serviceImp dao daoImp serviceImp中要注入 new dao new daoImp service 和dao都是interface 接口 1 public boolean addEmp Myemployee myemployee service 2 public boolean addEmp Myemployee myemployee dao EmployeeDaoImp的add方法中要try this getHibernateTemplate save myemployee return true catch DataAccessEx

温馨提示

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

评论

0/150

提交评论