CRM综合练习-SSH框架
一:搭建开发环境
第一步:创建web项目,引入jar包
第二步:引入配置文件
- Struts2的框架
-
- web.xml
- web.xml
-
- struts.xml
- Spring的框架
-
- jdbc.properties
-
- log4j.properties
-
- applicationContexr.xml
-
- web.xml
- Hibernate的框架
-
- hibernate.cfg.xml —交给Spring管理
第三步:创建相关包结构
- hibernate.cfg.xml —交给Spring管理
第四步:引入相关页面`
第五步:创建相关的类
1.创建实体类,写出set/get方法
2.创建Dao接口,写出实现类
3.写出用户管理Service接口,写出实现类
4.用户管理的Action类
第六步:将相关的类配置到Spring中
二:用户模板-用户注册代码实现
- 提供一个注册页面
login.jsp regist.jsp
<-- 由登陆跳转注册,登陆页面-->
<head>
<script type="text/javascript">
function registUI() {
window.location = "${ pageContext.request.contextPath }/regist.jsp";
}
</script>
</head>
<body>
<form id="loginForm" action="${pageContext.request.contextPath}/user_login.action" method="post" novalidate="novalidate">
用户名:<input type="text" id="username" name="username" class="text" maxlength="20">
密码:<input type="password" id="password" class="text" maxlength="20" autocomplete="off">
<input type="submit" value="登录" class="submit">
<input type="button" value="注册" onclick="registUI()" />
</form>
</body>
<--注册页面-->
<form id="registForm" action="${pageContext.request.contextPath}/user_regist.action" method="post" novalidate="novalidate">
用户名:<input type="text" id="username" name="username" class="text" maxlength="20">
密码:<input type="password" id="password" class="text" maxlength="20" autocomplete="off">
<input type="submit" value="注册" class="submit">
</form>
2 数据库创建表
3 创建实体类User和映射
4 编写Action
在Action中注入Service
在struts的配置中添加Action的访问方式
5 编写Service
注入Dao
6 编写Dao
整合Hinernate
在Dao中继承HibernateDaoSupport
在Dao中注入SessionFactory
7 配置Spring的事务管理
- 配置事务管理器
- 开启事务
- 在业务层添加事务注解