Struts hibernate Spring整合示例

  1. 添加struts2 的jar包:在源文件中有个example中的blank项目中的默认jar包

  1. 加入spring支持jar包:

  1. 添加hibernate支持
  2. 导入spring包

5,创建包和文件

数据库创建脚本:

DROP DATABASE IF EXISTS `test`;

CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET gbk */;

USE `test`;

CREATE TABLE `employee` (

`EmployeeId` varchar(32) NOT NULL,

`EmployeeName` varchar(32) NOT NULL,

PRIMARY KEY (`EmployeeId`)

) ENGINE=InnoDB DEFAULT CHARSET=gbk;

 

  1. 修改web.xml使项目支持struts2

struts2

org.apache.struts2.dispatcher.FilterDispatcher

    

        struts2

        /*

    

org.springframework.web.context.ContextLoaderListener

    

 

6,将数据库对应表映射增加到hibernate映射中

package pojo;

 

publicclass Employee implements java.io.Serializable {

 

    privatestaticfinallongserialVersionUID = 7430294674934594308L;

    private String employeeId;

    private String employeeName;

 

    public Employee() {

    }

 

    public Employee(String employeeName) {

        this.employeeName = employeeName;

    }

 

    public String getEmployeeId() {

        returnthis.employeeId;

    }

 

    publicvoid setEmployeeId(String employeeId) {

        this.employeeId = employeeId;

    }

 

    public String getEmployeeName() {

        returnthis.employeeName;

    }

 

    publicvoid setEmployeeName(String employeeName) {

        this.employeeName = employeeName;

    }

 

}

 

 

xml version="1.0" encoding="utf-8"?>

DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

你可能感兴趣的:(Struts hibernate Spring整合示例)