Struts21+Spring30+hibernate33全自动整合教程Word文件下载.docx
- 文档编号:19521521
- 上传时间:2023-01-07
- 格式:DOCX
- 页数:18
- 大小:485.49KB
Struts21+Spring30+hibernate33全自动整合教程Word文件下载.docx
《Struts21+Spring30+hibernate33全自动整合教程Word文件下载.docx》由会员分享,可在线阅读,更多相关《Struts21+Spring30+hibernate33全自动整合教程Word文件下载.docx(18页珍藏版)》请在冰豆网上搜索。
然后点击进入.
点击空白区域.右键new一个DateBaseDriver
如果成功的话会显示
准备工作完成以后继续向工程里面添加String3.0
点击工程右键---》MyEclipse-AddSpringCapabilities我就不截图了…
我还是个菜鸟.我知道有些jar包没有.但是我看SSH书上说引用的这些.但是我怕缺少jar包的原因就没敢删…(内本书真的很垃圾..我在当当网买的--)
然后点击Next然后Finsh
然后添加hibernate3.3
添加方法点击工程右键---》MyEclipse-AddhibernateCapabilities我就不截图了…
选择默认就可以点击Next
选择把hibernate整合到Spring配置文件中….点击Next
把SessionFactory整合到Spring配置文件中….点击Next。
。
选择你要选择刚才准备好的数据源…
点击Next
选择不需要创建SessionFactory点击Finish
然后导入asm-3.2.jar(此jar包如果没有我发给你…)
此时SSH框架只差最后一步了。
就是创建持久化类,与配置文件.及其该持久化类的Dao这时候你想到了什么?
没错,hibernate反映射..返回到DateBaseDriver成功界面…
点击进入……
这个页面
选择ID的生成方式…如果是Oracle数据库想跟Mysql一样想自增的话.那么可是使用PL/SQLDeveloper
自带的存储过程.然后在Userinfo.hbm.xml里面加入
如此怀念MySql哎….
然后点击NextFinsh…
同事创建2个包.
一个dao包…和一个action包。
把自动生成的UserinfoDAO转移到dao包里面.然后在action包里面创建一个UserinfoAction
如图所示
继续向Spring文件里面加入
将Dao对象注入到Action里面…继续在Struts2.1配置文件里面加入
然后在web.xml里面加入
由于小工程是在次强调只为面试所以忽略service层,忘各位谅解--.
添加成功
JSP代码…
<
%@pagelanguage="
java"
import="
java.util.*"
pageEncoding="
UTF-8"
%>
%
Stringpath=request.getContextPath();
html>
<
body>
formaction="
textAction.action"
method="
post"
>
请输入你要添加的用户名:
inputtype="
text"
name="
username"
/>
br/>
请输入你要添加的密码:
password"
<
submit"
value="
提交"
/form>
/body>
/html>
Web.xml代码
?
xmlversion="
1.0"
encoding="
web-appversion="
2.5"
xmlns="
xmlns:
xsi="
http:
//www.w3.org/2001/XMLSchema-instance"
xsi:
schemaLocation="
welcome-file-list>
welcome-file>
index.jsp<
/welcome-file>
/welcome-file-list>
context-param>
param-name>
contextConfigLocation<
/param-name>
param-value>
classpath:
applicationContext.xml<
/param-value>
/context-param>
listener>
listener-class>
org.springframework.web.context.ContextLoaderListener<
/listener-class>
/listener>
filter>
filter-name>
struts2<
/filter-name>
filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
/filter-class>
/filter>
filter-mapping>
url-pattern>
*.action<
/url-pattern>
/filter-mapping>
/web-app>
Action代码
packagecom.cxc.action;
importcom.cxc.dao.UserinfoDAO;
importcom.cxc.model.Userinfo;
publicclassUserinfoAction{
privateUserinfoDAOuserinfodao;
privateStringusername;
privateStringpassword;
publicStringtext(){
Userinfouserinfo=newUserinfo();
userinfo.setUsername(this.getUsername());
userinfo.setPassword(this.getPassword());
this.getUserinfodao().save(userinfo);
return"
success"
;
}
publicStringgetUsername(){
returnusername;
publicvoidsetUsername(Stringusername){
this.username=username;
publicStringgetPassword(){
returnpassword;
publicvoidsetPassword(Stringpassword){
this.password=password;
publicUserinfoDAOgetUserinfodao(){
returnuserinfodao;
publicvoidsetUserinfodao(UserinfoDAOuserinfodao){
this.userinfodao=userinfodao;
}
在次声明.如果有什么不对的地方:
敬请谅解….
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Struts21 Spring30 hibernate33 全自动 整合 教程