–声明,本博客仅本人用于学习笔记
三大框架:
Struts框架
1. params拦截器: 请求数据封装
2. 类型转换/数据处理
3. struts配置
4. 文件上传/下载/国际化处理
5. 数据效验/拦截器
6. Ognl表达式
7. 数据回显/模型驱动/防止表单重复提交

Hibernate框架
1. Api简介
2. 映射
多对一/一对多: 部门与员工
多对多/一对一
集合映射/组件映射/继承映射
3. Hibernate 缓存
4. 常用属性:inverse/lazy/cascade
5. 对象状态:临时/持久/游离

Spring框架
1) Spring IOC容器 【Inversion Of Control,即控制反转】
创建对象/处理对象依赖关系
2) Aop编程
3) Spring声明式事务管理
4) 框架整合
Spring与Struts
Spring与Hibernate
5)Spring对jdbc、hibernate操作的封装
JdbcTemplate (dataSource)/ HibernateTemplate(SessionFactory)

目标:
案例 【软件项目声明周期】

  1. 需求分析
    系统概述:
    企业人事管理系统!
    要求对员工信息进行维护;
    后台系统先登陆,才能操作员工: 添加/修改/删除
    没有登陆,只能查看列表,不能操作!

功能分类:
【管理员模块:】
注册/登陆
【员工模块】
1) 添加一个员工, 指定添加的部门
2) 对指定的员工信息修改
3) 删除选择员工
4)列表展示

  1. 设计
    2.1 系统设计
    【系统架构师/技术经理】
    主要做下面的事情,
    1) 搭建系统框架结构
    (基于mvc结构应用)
    2) 确定项目的关键点/难点
    3) 确定引用组件、公用类的版本
    Struts2.3
    Hibernate3.6
    Spring3.2
    2.2 数据库设计
    管理员表: t_admin
    员工表: t_employee
    部门: t_dept

  2. 代码
    步骤分析
    编码顺序:

    1) 设计数据库: hib_demo
    建表: t_admin/t_employee/t_dept
    2) 建立web项目、引入jar文件、准备环境
    …..

    3) 设计javvabean、写映射
    Admin.java 封装管理员
    Employee.java 员工
    Dept.java 部门

    Admin.hbm.xml
    Employee.hbm.xml
    Dept.hbm.xml
    

    4) Dao设计接口
    IAdminDao.java 管理员模块
    void save(Admin admin);
    Admin findByAdmin(Admin admin);
    IDeptDao.java 部门模块
    List getAll();
    Dept findById(int id);
    IEmployeeDao.java 员工模块
    Void save(Employee emp);
    Void update(Employee emp);
    Void delete(int id);
    Employee findById(int id);
    List getAll();
    List getAll(String employeeName);
    5) Dao接口实现

    6)Service接口设计
    IAdminService.java 管理员模块
    void register(Admin admin);
    Admin login(Admin admin);
    7)Service接口实现
    8) Action实现
    EmployeeAction.java 员工模块
    AdminAction.java 管理员模块
    9)jsp页面
    Index.jsp/list.jsp 首页列表
    http://localhost:8080/项目 首页列表

优化部分:
10) 用户登陆拦截器
UserInterceptor.java 检查是否登陆
只有登陆才能操作; 否则只能查看
11) Dao 操作优化
BaseDao.java 所有dao的通用方法,dao都必须继承此类
(反射泛型)

实现步骤代码:

1) 设计数据库: hib_demo
CREATE TABLE t_admin(
id INT PRIMARY KEY AUTO_INCREMENT,
adminName VARCHAR(20),
pwd VARCHAR(20)
)
表: t_dept/ t_employee
2) 建立web项目、引入jar文件、准备环境
【struts相关jar】
commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
commons-lang3-3.1.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
ognl-3.0.5.jar
struts2-core-2.3.4.1.jar
xwork-core-2.3.4.1.jar

【hibernate 相关 jar】
antlr-2.7.6.jar
commons-collections-3.1.jar
dom4j-1.6.1.jar
hibernate3.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar
javassist-3.12.0.GA.jar
jta-1.1.jar
slf4j-api-1.6.1.jar

【Spring-core】
commons-logging-1.1.3.jar
spring-beans-3.2.5.RELEASE.jar
spring-context-3.2.5.RELEASE.jar
spring-core-3.2.5.RELEASE.jar
spring-expression-3.2.5.RELEASE.jar

【Spring-web】
spring-web-3.2.5.RELEASE.jar
struts2-spring-plugin-2.3.4.1.jar

【Spring-Aop】
aopalliance.jar
aspectjrt.jar
aspectjweaver.jar
spring-aop-3.2.5.RELEASE.jar

【Spring-orm】
c3p0-0.9.1.2.jar
mysql-connector-java-5.1.12-bin.jar
spring-orm-3.2.5.RELEASE.jar
spring-tx-3.2.5.RELEASE.jar
spring-jdbc-3.2.5.RELEASE.jar

结构图



3) 设计javabean、写映射

public class Admin {private int id;private String adminName;private String pwd;
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"><hibernate-mapping package="cn.itcast.entity"><class name="Admin" table="t_admin"><id name="id"><generator class="native"></generator></id><property name="adminName" length="20"></property><property name="pwd" length="20"></property></class></hibernate-mapping>
public class Dept {private int id;private String name;
}
<hibernate-mapping package="cn.itcast.entity"><class name="Dept" table="t_dept"><id name="id" column="deptId"><generator class="native"></generator></id><property name="name" column="deptName"></property></class></hibernate-mapping>
public class Employee {private int id;private String empName;private double salary;private Dept dept;
}
<hibernate-mapping package="cn.itcast.entity"><class name="Employee" table="t_employee"><id name="id" column="empId"><generator class="native"></generator></id><property name="empName"></property><property name="salary"></property><!-- 多对一 --><many-to-one name="dept" column="dept_id" class="Dept"></many-to-one></class></hibernate-mapping>

4) Dao设计接口

IBaseDao

/*** 所有dao的通用操作接口定义**/
public interface IBaseDao<T> {/*** 保存* @param emp*/void save(T emp);/*** 跟新对象信息* @param emp*/void update(T emp);/*** 根据主键删除* @param id*/void delete(int id);/*** 根据主键查询* @param id* @return*/T findById(int id);/*** 查询全部* @return*/List<T> getAll();}
/*** 部门模块dao接口设计* */
public interface IDeptDao {/*** 查询全部* @return 返回全部信息*/List<Dept> getAll();/*** 根据主键查询* @param id  主键* @return 返回查询后的结果*/Dept findById(int id);}
/*** 员工模块dao接口设计*/
public interface IEmployeeDao {/*** 保存员工* @param emp*/void save(Employee emp);/*** 跟新员工信息* @param emp*/void update(Employee emp);/*** 根据主键删除* @param id*/void delete(int id);/*** 根据主键查询* @param id* @return*/Employee findById(int id);/*** 查询全部* @return*/List<Employee> getAll();/*** 根据员工名称条件查询* @param employeeName* @return*/List<Employee> getAll(String employeeName);}
/*** 管理员模块dao接口* */
public interface IAdminDao {/*** 保存* @param admin  管理员对象*/void save(Admin admin);/*** 根据管理员信息查询* @param admin  管理员对象* @return  返回查询后的结果*/Admin findByAdmin(Admin admin);}

Dao实现方法

/*** 所有dao的通用操作,希望所有的dao都继承此类* ** @param <T>*/
public class BaseDao<T> implements IBaseDao<T> {// 当前操作的实际的bean类型private Class<T> clazz;// 获取类名称private String className;// 反射泛型public BaseDao(){Type type = this.getClass().getGenericSuperclass();// 转换为参数化类型ParameterizedType pt = (ParameterizedType) type;  // BaseDao<Employee>// 得到实际类型Type types[] = pt.getActualTypeArguments();// 获取实际类型clazz = (Class<T>) types[0];className = clazz.getSimpleName();//例如:Employee}// 容器注入private SessionFactory sessionFactory;public void setSessionFactory(SessionFactory sessionFactory) {this.sessionFactory = sessionFactory;}public SessionFactory getSessionFactory() {return sessionFactory;}@Overridepublic void delete(int id) {sessionFactory.getCurrentSession().createQuery("delete from " + className + " where id=?").setParameter(0, id).executeUpdate();}@SuppressWarnings("unchecked")@Overridepublic T findById(int id) {return (T) sessionFactory.getCurrentSession().get(clazz, id);}@SuppressWarnings("unchecked")@Overridepublic List<T> getAll() {return sessionFactory.getCurrentSession().createQuery("from " + className).list();}@Overridepublic void save(T t) {sessionFactory.getCurrentSession().save(t);}@Overridepublic void update(T t) {sessionFactory.getCurrentSession().update(t);}}
public class AdminDao implements IAdminDao {// IOC容器(依赖)注入SessionFactory对象private SessionFactory sessionFactory;public void setSessionFactory(SessionFactory sessionFactory) {this.sessionFactory = sessionFactory;}@Overridepublic Admin findByAdmin(Admin admin) {return (Admin) sessionFactory.getCurrentSession()//.createQuery("from Admin where adminName=? and pwd=?")//.setString(0, admin.getAdminName())//.setString(1, admin.getPwd())//.uniqueResult();}@Overridepublic void save(Admin admin) {sessionFactory.getCurrentSession().save(admin);}}
public class DeptDao implements IDeptDao {// 容器注入private SessionFactory sessionFactory;public void setSessionFactory(SessionFactory sessionFactory) {this.sessionFactory = sessionFactory;}@Overridepublic Dept findById(int id) {return (Dept) sessionFactory.getCurrentSession().get(Dept.class, id);}@SuppressWarnings("unchecked")@Overridepublic List<Dept> getAll() {return sessionFactory.getCurrentSession().createQuery("from Dept").list();}}
public class EmployeeDao extends BaseDao<Employee> implements IEmployeeDao {@SuppressWarnings("unchecked")@Overridepublic List<Employee> getAll(String employeeName) {return getSessionFactory().getCurrentSession()//.createQuery("from Employee where empName like ?")//.setParameter(0, "%" +employeeName + "%")//.list();}@Overridepublic Employee findById(int id) {String hql = "from Employee e left join fetch e.dept where e.id=?";         return (Employee) getSessionFactory().getCurrentSession().createQuery(hql).setParameter(0, id).uniqueResult();}}

5) Service设计接口

/*** 管理员业务逻辑层接口* * * */
public interface IAdminService {/*** 注册* @param admin*/void register(Admin admin);/*** 登陆* @param admin* @return*/Admin login(Admin admin);}
/*** 部门模块业务逻辑层接口* **/
public interface IDeptService {/*** 查询全部* @return 返回全部信息*/List<Dept> getAll();/*** 根据主键查询* @param id  主键* @return 返回查询后的结果*/Dept findById(int id);
}
/*** 员工模块业务逻辑层接口* **/
public interface IEmployeeService {/*** 保存员工* @param emp*/void save(Employee emp);/*** 跟新员工信息* @param emp*/void update(Employee emp);/*** 根据主键查询* @param id* @return*/Employee findById(int id);/*** 查询全部* @return*/List<Employee> getAll();/*** 根据员工名称条件查询* @param employeeName* @return*/List<Employee> getAll(String employeeName);/*** 根据主键删除* @param id*/void delete(int id);/***  删除多个员工*/void deleteMany(int[] ids);}

Service实现

public class AdminService implements IAdminService {// 注入dao  【这里一定要用接口接收】private IAdminDao adminDao; //JDKpublic void setAdminDao(IAdminDao adminDao) {this.adminDao = adminDao;}   @Overridepublic Admin login(Admin admin) {return adminDao.findByAdmin(admin);}@Overridepublic void register(Admin admin) {adminDao.save(admin);}}
public class DeptService implements IDeptService {private IDeptDao deptDao;public void setDeptDao(IDeptDao deptDao) {this.deptDao = deptDao;}@Overridepublic Dept findById(int id) {return deptDao.findById(id);}@Overridepublic List<Dept> getAll() {return deptDao.getAll();}}
public class EmployeeService implements IEmployeeService {// 容器注入private IEmployeeDao  employeeDao;public void setEmployeeDao(IEmployeeDao employeeDao) {this.employeeDao = employeeDao;}@Overridepublic void delete(int id) {employeeDao.delete(id);}@Overridepublic void deleteMany(int[] ids) {if (ids != null && ids.length >0) {for (int id : ids){delete(id);}}}@Overridepublic Employee findById(int id) {return employeeDao.findById(id);}@Overridepublic List<Employee> getAll() {return employeeDao.getAll();}@Overridepublic List<Employee> getAll(String employeeName) {return employeeDao.getAll(employeeName);}@Overridepublic void save(Employee emp) {employeeDao.save(emp);}@Overridepublic void update(Employee emp) {employeeDao.update(emp);}}

6) Action设计

/*** 管理员登陆注册模块* 1. 登陆* **/
public class AdminAction extends ActionSupport implements ModelDriven<Admin> {// 封装请求数据private Admin admin = new Admin();public void setAdmin(Admin admin) {this.admin = admin;}public Admin getAdmin() {return admin;}@Overridepublic Admin getModel() {return admin;}// 调用Serviceprivate IAdminService adminService;public void setAdminService(IAdminService adminService) {this.adminService = adminService;}/*** 登陆*/public String login(){// 登陆验证Admin adminInfo = adminService.login(admin);// 验证if (adminInfo == null){// 登陆失败return "loginFaild";} else {// 登陆成功, 保存数据到sessionActionContext.getContext().getSession().put("adminInfo", adminInfo);return "index";}}}
/*** 员工模块控制器开发:* 1. 员工列表展示* 2. 添加员工* 3. 修改员工信息* 5. 删除* **/
public class EmployeeAction extends ActionSupport implements ModelDriven<Employee>, RequestAware{/*******一、封装数据********/private Employee employee = new Employee();   // 【模型驱动】// 封装请求的部门id(下拉列表的实际的值)private int deptId;public void setEmployee(Employee employee) {this.employee = employee;}public Employee getEmployee() {return employee;}public void setDeptId(int deptId) {this.deptId = deptId;}public int getDeptId() {return deptId;}@Overridepublic Employee getModel() {return employee;   // 返回实例化后的对象}/*******二、注入员工Service********/private IEmployeeService employeeService;public void setEmployeeService(IEmployeeService employeeService) {this.employeeService = employeeService;}// 部门Serviceprivate IDeptService deptService;public void setDeptService(IDeptService deptService) {this.deptService = deptService;}/*** 1. 员工列表展示*/public String list() {// 查询所有员工List<Employee> listEmp = employeeService.getAll();// 保存到requestrequest.put("listEmp", listEmp);return "list";}/*** 2. 添加员工 - 进入添加页面*/public String viewAdd(){// 查询所有部门信息, 保存到requestList<Dept> listDept = deptService.getAll();request.put("listDept", listDept);return "add";}/*** 2. 添加员工 - 添加员工数据*/public String save(){// 先根据部门主键查询Dept dept = deptService.findById(deptId);// 设置到员工对象中employee.setDept(dept);// 调用Service,保存员工employeeService.save(employee);return "listAction";  // 重定向到Action}/***  3. 修改员工信息 - 进入修改视图*/public String viewUpdate(){// 获取要修改的记录的idint id = employee.getId();// 1. 根据员工的主键查询  (lazy="false")Employee emp = employeeService.findById(id);  // 已经有部门信息// 2. 查询所有的部门List<Dept> listDept =  deptService.getAll();// 数据回显ValueStack vs = ActionContext.getContext().getValueStack();vs.pop();// 移除栈顶元素vs.push(emp); // 入栈// 保存request.put("listDept", listDept);return "edit";}/***  4. 修改员工信息 - 确认修改*/public String update() {//1. 先根据部门id, 查询部门对象; 再设置到员工属性中Dept dept = deptService.findById(deptId);employee.setDept(dept);//2. 更新员工employeeService.update(employee);return "listAction";  // 重定向到列表}/***  5. 修改员工信息 - 删除*/public String delete(){// 获取要删除员工的主键int empId = employee.getId();// 调用service删除employeeService.delete(empId);return "listAction";}// 接收框架运行时候传入的代表request对象的mapprivate Map<String, Object> request;@Overridepublic void setRequest(Map<String, Object> request) {this.request = request;}
}

7)拦截器

/*** 效验用户是否登陆,只有登陆后才可以进行操作。* 没有登陆,只能查看列表,不能操作!* **/
public class UserInterceptor extends AbstractInterceptor {@Overridepublic String intercept(ActionInvocation invocation) throws Exception {// 得到当前执行的方法String methodName = invocation.getProxy().getMethod();// 得到ActionContext对象ActionContext ac = invocation.getInvocationContext();// 获取session, 从session中获取登陆的管理员账号Object obj = ac.getSession().get("adminInfo");// 判断:if (!"login".equals(methodName) && !"list".equals(methodName)){// 验证if (obj == null){// 没有登陆return "login";} else {// 执行Actionreturn invocation.invoke();}} else {// 允许访问登陆、列表展示return invocation.invoke();}}}

配置文件 bean.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"><!-- 引入其他配置文件 --><import resource="config/bean-base.xml"/><import resource="config/bean-dao.xml"/><import resource="config/bean-service.xml"/><import resource="config/bean-action.xml"/>
</beans

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"><struts><package name="emp" extends="struts-default"><!-- 拦截器配置 --><interceptors><interceptor name="userInterceptor" class="cn.itcast.action.UserInterceptor"></interceptor><interceptor-stack name="myStack"><interceptor-ref name="defaultStack"></interceptor-ref><interceptor-ref name="userInterceptor"></interceptor-ref></interceptor-stack></interceptors><!-- 执行指定的拦截器 --><default-interceptor-ref name="myStack"></default-interceptor-ref><!-- 全局视图 --><global-results><result name="success">/index.jsp</result><result name="login" type="redirect">/login.jsp</result><!-- 错误视图配置 --><result name="null">/error/null.jsp</result><result name="error">/error/error.jsp</result></global-results><!-- 全局异常 --><global-exception-mappings><!-- result 会取找全局视图的名称 --><exception-mapping result="null" exception="java.lang.NullPointerException"></exception-mapping><exception-mapping result="error" exception="java.lang.Exception"></exception-mapping></global-exception-mappings><!-- Ation实例交给spring容器创建 --><!-- 员工Action --><action name="emp_*" class="employeeAction" method="{1}"><!-- 列表展示 --><result name="list">/WEB-INF/list.jsp</result><!-- 进入添加页面视图 --><result name="add">/WEB-INF/add.jsp</result><!-- 添加成功,进入列表 (防止刷新就多一条记录问题,所以用重定向) --><result name="listAction" type="redirectAction">emp_list</result><!-- 进入修改页面 --><result name="edit">/WEB-INF/edit.jsp</result></action><!-- 管理员Action --><action name="admin_*" class="adminAction" method="{1}"><!-- 登陆失败 --><result name="loginFaild">/login.jsp</result><!-- 登陆成功 --><result name="index" type="redirectAction">emp_list</result></action></package></struts>

8)config配置文件

bean-base.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"><!-- 1. 连接池实例 --><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="jdbcUrl" value="jdbc:mysql://localhost:3306/hib_demo"></property><property name="driverClass" value="com.mysql.jdbc.Driver"></property><property name="user" value="root"></property><property name="password" value="root"></property><property name="initialPoolSize" value="3"></property><property name="maxPoolSize" value="6"></property></bean><!-- 2. Spring管理SessionFactory 【全部配置都写到spring中】 --><!-- # 注入DataSource、 注入常用配置属性、映射配置属性 --><bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><property name="dataSource" ref="dataSource"></property><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop><prop key="hibernate.show_sql">true</prop><prop key="hibernate.hbm2ddl.auto">update</prop></props></property><property name="mappingLocations"><list><value>classpath:cn/itcast/entity/*.hbm.xml</value></list></property></bean><!-- 3. 事务相关配置 --><!-- 3.1 事务管理器类 --><bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory"></property></bean><!-- 3.2 事务增强(如何管理事务)--><tx:advice id="txAdvice" transaction-manager="txManager"><tx:attributes><tx:method name="get*" read-only="true"/><tx:method name="find*" read-only="true"/><tx:method name="*" read-only="false"/></tx:attributes></tx:advice><!-- 3.3 Aop配置 = 切入点表达式(拦截目标对象,生成代理)  + 事务增强应用--><aop:config><aop:pointcut expression="execution(* cn.itcast.service.impl.*.*(..))" id="pt"/><aop:advisor advice-ref="txAdvice" pointcut-ref="pt"/></aop:config>
</beans>     

bean-dao.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"><!-- Dao 注入 SessionFactory --><bean id="adminDao" class="cn.itcast.dao.impl.AdminDao"><property name="sessionFactory" ref="sessionFactory"></property></bean><bean id="deptDao" class="cn.itcast.dao.impl.DeptDao"><property name="sessionFactory" ref="sessionFactory"></property></bean><bean id="employeeDao" class="cn.itcast.dao.impl.EmployeeDao"><property name="sessionFactory" ref="sessionFactory"></property></bean>
</beans>     

bean-service.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"><!-- Service 需要注入 Dao --><bean id="adminService" class="cn.itcast.service.impl.AdminService"><property name="adminDao" ref="adminDao"></property></bean><bean id="deptService" class="cn.itcast.service.impl.DeptService"><property name="deptDao" ref="deptDao"></property></bean><bean id="employeeService" class="cn.itcast.service.impl.EmployeeService"><property name="employeeDao" ref="employeeDao"></property></bean>
</beans>     

bean-action.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"><!-- Action中需要注入Service --><!-- 1. 员工管理模块 --><bean id="employeeAction" class="cn.itcast.action.EmployeeAction" scope="prototype"><property name="employeeService" ref="employeeService"></property><property name="deptService" ref="deptService"></property></bean><!-- 2. 管理员模块 --><bean id="adminAction" class="cn.itcast.action.AdminAction" scope="prototype"><property name="adminService" ref="adminService"></property></bean>
</beans>     

9)Jsp编写

heand.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s" %><!-- 判断:如果用户登陆: 显示欢迎你,退出 -->
<!-- 判断:如果用户没有登陆: 显示登陆、注册 -->
<div align="center" style="width:80% "><s:if test="#session.adminInfo != null">欢迎你: <s:property value="#session.adminInfo.adminName"/> &nbsp;<s:a href="#">退出</s:a><s:a href="emp_viewAdd">添加员工</s:a>
</s:if>
<s:else><s:a href="login.jsp">登陆</s:a><s:a href="register.jsp">注册</s:a>
</s:else>
</div> 

index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%--response.sendRedirect(request.getContextPath() + "/emp_list.action");
--%><%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:redirect url="/emp_list.action"></c:redirect>

login.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s" %><html><head><title>添加</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    </head><body>    <s:form action="/admin_login" method="post" theme="simple"><table border="1" align="center" cellpadding="5" cellspacing="0"><tr><td>管理员账号</td><td><s:textfield name="adminName" id="adminName" value=""></s:textfield></td></tr><tr><td>密码:</td><td><s:textfield name="pwd" id="pwd" value=""></s:textfield></td></tr><tr><td colspan="2"><s:submit value="登陆"></s:submit></td></tr></table></s:form></body>
</html>

17、简单的企业人事管理系统(ssh)相关推荐

  1. 企业hr管理java,hr Java 企业人事管理系统,利用SSH模式进行开发,能满足一般 的得需求。 Develop 238万源代码下载- www.pudn.com...

    开发工具: Java 文件大小: 880 KB 上传时间: 2015-03-17 下载次数: 4 提 供 者: 王金元 详细说明:Java 企业人事管理系统,利用SSH模式进行开发,能满足一般企业的得 ...

  2. java企业人事管理系统源码_基于Java+SSH的企业人事管理系统

    需求分析 基于Spring, Struts2, Hibernate,Java 实现一个企业人事管理系统, 实现 权限管理.人事管理.考勤管理.数据统计等.主要功能为签到.请假.离岗及数据汇总的功能 本 ...

  3. ssm基于Java的微小企业人事管理系统的设计与实现毕业设计源码231012

    ssm微小企业人事管理系统的设计与实现 摘 要 科技进步的飞速发展引起人们日常生活的巨大变化,电子信息技术的飞速发展使得电子信息技术的各个领域的应用水平得到普及和应用.信息时代的到来已成为不可阻挡的时 ...

  4. (附源码)ssm+mysql+基于Java的微小企业人事管理系统的设计与实现 毕业设计231012

    ssm微小企业人事管理系统的设计与实现 摘 要 科技进步的飞速发展引起人们日常生活的巨大变化,电子信息技术的飞速发展使得电子信息技术的各个领域的应用水平得到普及和应用.信息时代的到来已成为不可阻挡的时 ...

  5. ssm+mysql+基于Java的微小企业人事管理系统的设计与实现 毕业设计-附源码231012

    ssm微小企业人事管理系统的设计与实现 摘 要 科技进步的飞速发展引起人们日常生活的巨大变化,电子信息技术的飞速发展使得电子信息技术的各个领域的应用水平得到普及和应用.信息时代的到来已成为不可阻挡的时 ...

  6. 计算机毕业设计Java企业人事管理系统(源码+系统+mysql数据库+lw文档)

    计算机毕业设计Java企业人事管理系统(源码+系统+mysql数据库+lw文档) 计算机毕业设计Java企业人事管理系统(源码+系统+mysql数据库+lw文档) 本源码技术栈: 项目架构:B/S架构 ...

  7. java-php-python-ssm企业人事管理系统计算机毕业设计

    java-php-python-ssm企业人事管理系统计算机毕业设计 java-php-python-ssm企业人事管理系统计算机毕业设计 本源码技术栈: 项目架构:B/S架构 开发语言:Java语言 ...

  8. (附源码)基于BS结构的企业人事管理系统的设计与实现 毕业设计121727

    Springboot企业人事管理系统 摘 要 由于数据库和数据仓库技术的快速发展,企业人事管理系统建设越来越向模块化.智能化.自我服务和管理科学化的方向发展.人事管理系统对处理对象和服务对象,自身的系 ...

  9. java计算机毕业设计企业人事管理系统源程序+mysql+系统+lw文档+远程调试

    java计算机毕业设计企业人事管理系统源程序+mysql+系统+lw文档+远程调试 java计算机毕业设计企业人事管理系统源程序+mysql+系统+lw文档+远程调试 本源码技术栈: 项目架构:B/S ...

最新文章

  1. 史上最良心程序员,在代码注释里,告诉这家公司有多坑
  2. C#高性能大容量SOCKET并发(十一):编写上传客户端
  3. php 自动列,设置自动调整列phpExcel
  4. C语言试题六十八之请编写函数实现亲密数
  5. Linux 线程信号量同步
  6. Win11系统自动暂停更新后想继续怎么办 Win11系统重新启动更新教程
  7. Linux C++使用MySQL数据库
  8. Qt拖放操作和打印操作
  9. C语言oo1cpp怎么进,cpp 第八章第7题解决办法
  10. 水晶报表中对某一栏位值进行处理_终于有人讲清楚了,BI和报表的差异!
  11. C#网络编程----文件流
  12. 【收藏】DIABLO 2 CD KEY
  13. centos6.5命令行 安装锐起 RDV(Rich Desktop Virtualization)
  14. libyuv的编译使用
  15. SpringBoot + Vue 前后端分离的小案例
  16. 以P2P网贷为例互联网金融产品如何利用大数据做风控?
  17. jQuery 的表单验证之提交验证
  18. matlab 根据长轴,短轴,中心坐标画椭圆
  19. 用PV操作写出一个不会出现死锁的哲学家进餐问题
  20. 一只青蛙一次可以跳一级或二级台阶,请问跳n级台阶有多少次跳法之斐波那契数列的非递归写法

热门文章

  1. MoG EM-Algorithm
  2. template模板
  3. 如何在ubuntu 16.04上安装WebERP
  4. Linux df命令的使用
  5. [渝粤教育] 西北农林科技大学 成本会计学 参考 资料
  6. 写论文时,参考文献怎么引用?
  7. LeetCode 904. 水果成篮
  8. SWE_Browser编译
  9. 登陆mysql的命令行
  10. 在不同操作系统上安装Python的详细教程