ssh整合思路详解

这篇文章来自尚硅谷佟刚老师的视频总结,我只是想记录下我的博客方便自己复习  如果有什么不好行为请提醒


1. 加入 Spring

 

1). 加入 jar 包

2). 配置 web.xml 文件

3). 加入 Spring 的配置文件.

 

2. 加入 Hibernate

 

1). 同时建立持久化类, 和其对应的 .hbm.xml 文件, 生成对应的数据表

2). Spring 整合 Hibernate

3). 步骤:

 

①. 加入 jar 包

②. 在类路径下加入hibernate.cfg.xml 文件, 在其中配置 hibernate 的基本属性

③. 建立持久化类, 和其对应的 .hbm.xml 文件

④. 和 Spring 进行整合

 

i.  加入 c3p0 和 MySQL 的驱动

ii. 在 Spring 的配置文件中配置: 数据源, SessionFactory,声明式事务

 

⑤. 启动项目, 会看到生成对应的数据表

 

3. 加入 Struts2

 

1). 加入 jar 包: 若有重复的 jar 包, 则需要删除版本较低的.javassist-3.11.0.GA.jar

2). 在 web.xml 文件中配置 Struts2 的 Filter

3). 加入 Struts2 的配置文件

4). 整合 Spring

①. 加入 Struts2 的 Spring 插件的 jar 包

②. 在 Spring 的配置文件中正常配置 Action, 注意 Action 的 scope 为 prototype

③. 在 Struts2 的配置文件中配置 Action 时, class 属性指向该 Action 在 IOC 中的 id

 

4. 完成功能.

 

1). 获取所有的员工信息: 若在 Dao 中只查询 Employee 的信息, 而且 Employee 和 Department 还是使用的懒加载. 页面上还需要显示

员工信息, 此时会出现懒加载异常, 代理对象不能被初始化:2.org.hibernate.LazyInitializationException: could not initialize proxy - noSession

解决:

①. 打开懒加载: 不推荐使用

②. 获取 Employee 时使用 迫切左外连接同时初始化其关联的 Department 对象.

③. 使用OpenSessionInViewFilter: 后面再提.

 

2). 删除员工信息:

①. 正常删除, 返回值需要是 redirect 类型, 而且重定向到 emp-list

②. 确定要删除吗? 的提示使用 jQuery 完成

③. Ajax 的使用参见struts-2.3.15.3-all/struts-2.3.15.3/docs/WW/docs/ajax.html

 

3). 添加员工:

①. 显示表单页面: 需要先查询所有的部门信息

②. 使用 Struts2 的 ModelDriven 和 Preparable 拦截器

③. 时间是一个字符串, 需要转为一个 Date 类型的对象

 

碰到的问题:

java.lang.NoClassDefFoundError:org/hibernate/cfg/Configuration

 

解决方法:

You're getting the error because the hibernatelibraries are not available to Tomcat. In your picture, below the hibernatelibrary set there is an empty set called 'Web App Libraries' - this is the setyour hibernate libraries need to be in.

Right click your project -> Build Path ->Configure Build Path, and remove the hibernate set from the build path. Nowimport the jars into the WEB-INF/lib folder. Refresh your project and now youshould see them listed in the 'Web App Libraries' set (i appreciate this issomewhat annoying that you have to import them into your code base - someoneelse might know a better way to do this that doesn't involve copying the jarsin.

不能直接用myeclipse里面的hibernate自动添加的包只能手动添加包到web-inf / lib 包下面

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值