博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ssh框架整合完整版
阅读量:4481 次
发布时间:2019-06-08

本文共 5557 字,大约阅读时间需要 18 分钟。

1、导入jar包

  可以在src下添加一个log4j.properties文件来记录日志

2、加入实体类+映射文件

映射:从类入手class+属性

  a、映射的头文件在:hibernate3.jar-->org.hibernate-->hibernate-mapping-3.0.dtd

  b、type=“java.lang.String"根据属性来更改+column(加长度的时候要独立出来)

注意:如果有遇到entity not found   就要想到路径错误,映射文件中有那个package=”包名“还有就是在hibernate.cfg.xml的mappling那路径有没有正确

单据类型
单据编号
审核时间
审核类型
审核人
审核结果
审核意见
映射文件

hibernate.cfg.xml文件。头文件在:hibernate3.jar-->org.hibernate-->hibernate-configuration-3.0.dtd

hibernate.cfg.xml文件
jdbc:oracle:thin:@localhost:1521:jbit
rong
rong
oracle.jdbc.driver.OracleDriver
org.hibernate.dialect.OracleDialect
true
true

用spring的把hibernate.cfg.xml整合到applicationContext.xml文件中

先配置dataSource找BasicDataSource

然后在注入sessionFactory

applicationContext.xml文件刚开始写入下面的代码 
true
true
org.hibernate.dialect.Oracle10gDialect
cn/bdqn/jboa/entity/Position.hbm.xml
-->
classpath:cn/bdqn/jboa/entity/

 

 

3、创建dao、impl、biz包

4、a、创建applicationContext.xml-->Next-->CREATE SCHEMA FILE-->Next-->select xml catalog entry

  找beans-->next-->root element 改beans   其他不打勾。然后把prefix的前缀p删了

  add -->  aop文件和tx文件

 

  再添加p命名+context

  b、spring接管hibernate的创建工厂(使用hibernate.cfg.xml文件的方法,添加一个bean sessionFactory  找localSessionFactoryBean)

  注入一个属性 configLocation( 当前配置)

注入dao:

dao要工作的话,必须要一个sessionFactory(会话工厂),所以引用sessionFactory

dao继承hibernateDaoSupport就可以得到模板的属性,就可以使用getHibernateTemplate()方法

注入biz:biz调用dao所以属性那是dao

事务:

首先声明事务(多加注意,很容易忘了)+事务管理器transaction-manager(事务管理器的要求增删改)

tx:advice事务属性的配置增删改  织入切面时候要引用id

//查询用read-only=“true"会比较快点

织入切面:

接下去就是把业务层biz给action了

创建action和jsp界面

public class EmployeeAction {    //业务bean交给action    private EmployeeBiz employeeBiz;    //登录的话需要验证    private Employee employee;    //接收错误    private String message;
    //set和get忽略
    //登录
  public String login(){                Employee result = employeeBiz.checkLogin(employee);        if(result == null){            this.message="用户名或密码错误";            return "input";        }else{            ActionContext.getContext().getSession().put("employee", result);            //职位            ActionContext.getContext().getSession()            .put("employee_position", result.getPosition().getNameEn());                        return "success";        }    }

新建个struts.xml  (头文件去struts2-spring-plugin-2.3.16.3.jar找struts-plugin.xml)

struts和spring合作的结果(EmployeeAction类里找到employeeBiz会去applicationContext.xml中去找一样名字的biz,就这样注入进去)

所以命名得规范,因为自动装配时靠名字对应的。否则就改成类型

/index.jsp
/login.jsp

读取配置文件web.xml

contextConfigLocation
classpath:applicationContext.xml
org.springframework.web.context.ContextLoaderListener
OpenSessionInViewFilter
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
//这个一定要放在struts2的映射前面,因为取决于谁在前,谁先执行
OpenSessionInViewFilter
*.action
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*
index.jsp

就可以开始配置部署了。

 

转载于:https://www.cnblogs.com/xuerong/p/4949582.html

你可能感兴趣的文章
Winform WebBrowser引用IE版本问题
查看>>
pdf转换word
查看>>
redis.1--SDS结构
查看>>
laravel之路由汇总
查看>>
面向对象 【抽象类】【接口】【构造函数】【静态】
查看>>
34.闭包
查看>>
ScriptEngine执行复杂js报数组越界
查看>>
使用dbutils进行批处理
查看>>
通过Thrift访问HDFS分布式文件系统的性能瓶颈分析
查看>>
第四次迭代冲刺会议
查看>>
【leetcode 简单】 第五十九题 同构字符串
查看>>
adaboost算法
查看>>
启动关闭mongod
查看>>
max,min,Zip函数(十一)
查看>>
翻译:Windows and Real-Time——Daniel Terhell
查看>>
Git 的 .gitignore 配置
查看>>
9布局管理器
查看>>
JDK篇
查看>>
Redis客户端基本命令
查看>>
第6章 XHTML:Web重构
查看>>