CRM综合练习-SSH框架

一:搭建开发环境
第一步:创建web项目,引入jar包
CRM综合练习-SSH框架
CRM综合练习-SSH框架
第二步:引入配置文件

  • Struts2的框架
    • web.xml
      CRM综合练习-SSH框架
    • struts.xml
  • Spring的框架
    • jdbc.properties
    • log4j.properties
    • applicationContexr.xml
    • web.xml
  • Hibernate的框架
    • hibernate.cfg.xml —交给Spring管理
      第三步:创建相关包结构
      CRM综合练习-SSH框架

第四步:引入相关页面`

第五步:创建相关的类
CRM综合练习-SSH框架
1.创建实体类,写出set/get方法
CRM综合练习-SSH框架
2.创建Dao接口,写出实现类
CRM综合练习-SSH框架
CRM综合练习-SSH框架
3.写出用户管理Service接口,写出实现类
CRM综合练习-SSH框架
CRM综合练习-SSH框架
4.用户管理的Action类
CRM综合练习-SSH框架
第六步:将相关的类配置到Spring中
CRM综合练习-SSH框架

二:用户模板-用户注册代码实现

  1. 提供一个注册页面
    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和映射
CRM综合练习-SSH框架
4 编写Action
CRM综合练习-SSH框架
在Action中注入Service
CRM综合练习-SSH框架
在struts的配置中添加Action的访问方式
CRM综合练习-SSH框架
5 编写Service
CRM综合练习-SSH框架
注入Dao
CRM综合练习-SSH框架
6 编写Dao
整合Hinernate
CRM综合练习-SSH框架
在Dao中继承HibernateDaoSupport
CRM综合练习-SSH框架
在Dao中注入SessionFactory
CRM综合练习-SSH框架
7 配置Spring的事务管理

  • 配置事务管理器
  • 开启事务
    CRM综合练习-SSH框架
  • 在业务层添加事务注解
    CRM综合练习-SSH框架