Java Web开发 SSH配置文件案例详解(eclipse开发自存)

本文并没有具体的Dao,Service,Action代码实现,知识分享了下SSH整合框架中 那些配置文件的模板,仅供参考,有不对的地方欢迎大家指正

简单实例:实体类Departmentinfo 与 Employeeinfo 如下

package com.prj.bean;

import java.util.HashSet;
import java.util.Set;

/**
 * Departmentinfo entity. @author MyEclipse Persistence Tools
 */

public class Departmentinfo implements java.io.Serializable {

    // Fields

    private Integer departmentId;
    private String departmentName;
    private Set employeeinfos = new HashSet(0);

    // Constructors

    /** default constructor */
    public Departmentinfo() {
    }

    /** full constructor */
    public Departmentinfo(String departmentName, Set employeeinfos) {
        this.departmentName = departmentName;
        this.employeeinfos = employeeinfos;
    }

    // Property accessors

    public Integer getDepartmentId() {
        return this.departmentId;
    }

    public void setDepartmentId(Integer departmentId) {
        this.departmentId = departmentId;
    }

    public String getDepartmentName() {
        return this.departmentName;
    }

    public void setDepartmentName(String departmentName) {
        this.departmentName = departmentName;
    }

    public Set getEmployeeinfos() {
        return this.employeeinfos;
    }

    public void setEmployeeinfos(Set employeeinfos) {
        this.employeeinfos = employeeinfos;
    }

}
package com.prj.bean;

import java.sql.Timestamp;

/**
 * Employeeinfo entity. @author MyEclipse Persistence Tools
 */

public class Employeeinfo implements java.io.Serializable {

    // Fields

    private Integer employeeNo;
    private Departmentinfo departmentinfo;
    private String employeeName;
    private String job;
    private Double salary;
    private Timestamp birthday;

    // Constructors

    /** default constructor */
    public Employeeinfo() {
    }

    /** full constructor */
    public Employeeinfo(Departmentinfo departmentinfo, String employeeName,
            String job, Double salary, Timestamp birthday) {
        this.departmentinfo = departmentinfo;
        this.employeeName = employeeName;
        this.job = job;
        this.salary = salary;
        this.birthday = birthday;
    }

    // Property accessors

    public Integer getEmployeeNo() {
        return this.employeeNo;
    }

    public void setEmployeeNo(Integer employeeNo) {
        this.employeeNo = employeeNo;
    }

    public Departmentinfo getDepartmentinfo() {
        return this.departmentinfo;
    }

    public void setDepartmentinfo(Departmentinfo departmentinfo) {
        this.departmentinfo = departmentinfo;
    }

    public String getEmployeeName() {
        return this.employeeName;
    }

    public void setEmployeeName(String employeeName) {
        this.employeeName = employeeName;
    }

    public String getJob() {
        return this.job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    public Double getSalary() {
        return this.salary;
    }

    public void setSalary(Double salary) {
        this.salary = salary;
    }

    public Timestamp getBirthday() {
        return this.birthday;
    }

    public void setBirthday(Timestamp birthday) {
        this.birthday = birthday;
    }

}

映射文件:Departmentinfo.hbm.xml 与 Employeeinfo.hbm.xml

<?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">
<!--
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="com.prj.bean.Departmentinfo" table="departmentinfo" catalog="employeedb">
        <id name="departmentId" type="java.lang.Integer">
            <column name="DepartmentId" />
            <generator class="native" />
        </id>
        <property name="departmentName" type="java.lang.String">
            <column name="DepartmentName" length="20" />
        </property>
        <set name="employeeinfos" inverse="true">
            <key>
                <column name="Dept" />
            </key>
            <one-to-many class="com.prj.bean.Employeeinfo" />
        </set>
    </class>
</hibernate-mapping>
<?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">
<!--
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="com.prj.bean.Employeeinfo" table="employeeinfo" catalog="employeedb">
        <id name="employeeNo" type="java.lang.Integer">
            <column name="EmployeeNo" />
            <generator class="native" />
        </id>
        <many-to-one name="departmentinfo" class="com.prj.bean.Departmentinfo" fetch="select">
            <column name="Dept" />
        </many-to-one>
        <property name="employeeName" type="java.lang.String">
            <column name="EmployeeName" length="20" />
        </property>
        <property name="job" type="java.lang.String">
            <column name="Job" length="20" />
        </property>
        <property name="salary" type="java.lang.Double">
            <column name="Salary" precision="10" />
        </property>
        <property name="birthday" type="java.sql.Timestamp">
            <column name="Birthday" length="19" />
        </property>
    </class>
</hibernate-mapping>

主配置文件:hibernate.cfg.xml

<?xml version=‘1.0‘ encoding=‘UTF-8‘?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

    <session-factory>
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>
        <mapping resource="com/prj/bean/Departmentinfo.hbm.xml" />
        <mapping resource="com/prj/bean/Employeeinfo.hbm.xml" />

    </session-factory>

</hibernate-configuration>

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>

    <package name="emp" extends="struts-default" namespace="/">
        <action name="employee" class="employeeActionBean">
            <result name="succ">/index.jsp</result>
            <result name="remove_succ" type="redirect">/index.jsp</result>
        </action>

        <action name="department" class="departmentActionBean">
            <result name="succ">/index.jsp</result>
        </action>
    </package>
</struts>    

applicationContext.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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <!-- DataSource数据源 -->
    <bean id="dataSourceBean"
        class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName"
            value="com.mysql.jdbc.Driver">
        </property>
        <property name="url"
            value="jdbc:mysql://localhost:3306/employeedb?useUnicode=true&amp;characterEncoding=utf-8">
        </property>
        <property name="username" value="root"></property>
        <property name="password" value="liweidong"></property>
    </bean>

    <!-- SessionFactory -->
    <bean id="sessionFactoryBean"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

        <!-- 注入Hibernate的主配置文件hibernate.cfg.xml -->
        <property name="configLocation" value="classpath:hibernate.cfg.xml" />

        <!-- 注入DataSource数据源 -->
        <property name="dataSource" ref="dataSourceBean"/>
    </bean>

    <!-- DAO -->
    <!-- 抽象Bean -->
    <bean id="baseDaoBean" abstract="true">
        <property name="sessionFactory" ref="sessionFactoryBean"/>
    </bean>
    <bean id="employeeDaoBean" class="com.prj.dao.impl.EmployeeDao" parent="baseDaoBean"/>
    <bean id="departmentDaoBean" class="com.prj.dao.impl.DepartmentDao" parent="baseDaoBean"/>

    <!-- 业务层 -->
    <bean id="employeeServiceBean" class="com.prj.biz.impl.EmployeeService">
        <!-- 注入数据访问对象  -->
        <property name="employeeDao" ref="employeeDaoBean"/>
    </bean>

    <bean id="departmentServiceBean" class="com.prj.biz.impl.DepartmentService">
        <!-- 注入数据访问对象  -->
        <property name="departmentDao" ref="departmentDaoBean"/>
    </bean>

    <!-- WEB层 -->
    <bean id="employeeActionBean" class="com.prj.web.action.EmployeeAction">
        <!-- 注入业务对象 -->
        <property name="employeeService" ref="employeeServiceBean"/>
    </bean>

    <bean id="departmentActionBean" class="com.prj.web.action.DeparmentAction">
        <!-- 注入业务对象 -->
        <property name="departmentService" ref="departmentServiceBean"/>
    </bean>

</beans>

web.xml 的配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <display-name></display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  <!-- OpenSessionInViewFilter:用于解决延迟加载异常 -->
  <filter>
      <filter-name>OpenSessionInViewFilter</filter-name>
      <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>

      <!-- 设置spring容器中SessionFactory的bean名称 -->
      <init-param>
          <param-name>sessionFactoryBeanName</param-name>
          <param-value>sessionFactoryBean</param-value>
      </init-param>
  </filter>

  <filter-mapping>
      <filter-name>OpenSessionInViewFilter</filter-name>
      <url-pattern>/*</url-pattern>
  </filter-mapping>

  <filter>
      <filter-name>struts2</filter-name>
      <filter-class>
          org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
      </filter-class>
  </filter>
  <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!-- ContextLoaderListener的作用:在服务器启动时,加载Spring容器 -->
  <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <!-- 默认在WEB-INF下加载spring配置文件 -->
  <!-- 设置contextConfigLocation参数,用于指定spring配置文件的位置 -->
  <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:applicationContext.xml</param-value>
  </context-param>

</web-app>
时间: 2024-08-04 16:05:12

Java Web开发 SSH配置文件案例详解(eclipse开发自存)的相关文章

Python学习教程:WEB开发——Python WSGI协议详解

Web应用程序开发 Web应用程序的本质是什么 简单描述Web应用程序的本质,就是我们通过浏览器访问互联网上指定的网页文件展示到浏览器上. 流程如下图: 从更深层次一点的技术角度来看,由以下几个步骤: 浏览器,将要请求的内容按照HTTP协议发送服务端 服务端,根据请求内容找到指定的HTML页面 浏览器,解析请求到的HTML内容展示出来 HTTP协议的全称是HyperText Transfer Protocol(超文本传输协议) HTTP协议是我们常用的五层协议中的应用层(5层从上到下是应用层,传

微信小程序:开发入门及案例详解pdf

下载地址:网盘下载 本书可分为3部分,第一部分作为基础章节,介绍了第一个小程序的搭建流程,让大家能快速上手:同时对小程序框架原理进行了详细介绍,为后面学习组件.API打下基础. 第二部分对小程序组件.API进行介绍,对组件.API的使用.注意事项进行详细讲解,并给出示例代码. 最后一部分精选5个由浅入深的案例,对小程序研发进行实战讲解,涵盖了实际项目中可能涉及的技术方案和使用方法,具备很强的实战意义. 在这本书中,包含了作者在电商领域多年的前端经验总结和对当前主流架构的思考,希望读者们可以从中获

Java并发编程之---Lock框架详解

Java 并发开发:Lock 框架详解 摘要: 我们已经知道,synchronized 是Java的关键字,是Java的内置特性,在JVM层面实现了对临界资源的同步互斥访问,但 synchronized 粒度有些大,在处理实际问题时存在诸多局限性,比如响应中断等.Lock 提供了比 synchronized更广泛的锁操作,它能以更优雅的方式处理线程同步问题.本文以synchronized与Lock的对比为切入点,对Java中的Lock框架的枝干部分进行了详细介绍,最后给出了锁的一些相关概念. 一

《Tomcat与Java Web开发技术详解》思维导图

越想构建上层建筑,就越觉得底层基础很重要.补课系列. 书是良心书,就是太基础了,正适合补课. [纯文字版] Tomcat与Java Web开发技术详解 Servlet Servlet的生命周期 初始化 1Servlet容器加载Servlet类 2Servlet容器创建ServletConfig,初始化配置信息 3Servlet容器创建Servlet对象 4Servlet容器调用Servlet对象的init(ServletConfig) 时机:首次被请求或配置了<load-on-startup>

Java Web开发之详解JSP

JSP作为Java Web开发中比较重要的技术,一般当作视图(View)的技术所使用,即用来展现页面.Servlet由于其本身不适合作为表现层技术,所以一般被当作控制器(Controller)所使用,而JavaBean作为模型(Model)层使用.这就是经典的MVC模型. Servlet和JSP的关系上篇博客已经讲过了,并演示了一个相当简单的例子.在具体讲述JSP之前,先把JavaBean简单介绍一下. JavaBean其实就是一个Java普通类,定义了类的属性和行为(get.set方法).在M

SSH学习之路(一).Net开发与Java Web开发

摘要:一直再使用.net mvc5开发,期间学习过java web相关的知识,现如今想要进阶一下便开始学习ssh框架. 1..net web开发 对于微软的东西,开发者考虑的东西不需要太多,你新建一个项目几乎可以就可以跑起来,因为微软大大已经简化了所有较为复杂的配置处理,你基本上做很少的配置就可以开发一个项目,当然这个是针对于保证能跑起来就行.而对于高级web开发中,.net 开发也是属于较为有难度的,虽然入门容易但是深入真的需要花费很多时间,因为简单的入门导致很多开发者已经适应了ASP.NET

使用 jQuery Mobile 与 HTML5 开发 Web App —— jQuery Mobile 事件详解

在前文<使用 jQuery Mobile 与 HTML5 开发 Web App —— jQuery Mobile 默认配置与事件基础>中,Kayo 对 jQuery Mobile 事件的基础作出了一些说明,建议在阅读本文前首先阅读前文,这里 Kayo 再引用前文的重要内容. “jQuery Mobile 在基于本地事件上,创建了一系列的自定义事件,大部分事件是基于触摸设备的使用情况开发的,当然这些事件对于桌面环境也会有适当的处理,开发者可以使用 bind() 函数绑定到需要的页面对象中. 值得

基于DKHadoop的智慧政务服务平台开发案例详解

基于DKHadoop的智慧政务服务平台开发案例详解大数据技术的应用与发展正在让我们的生活经历一场深刻的"变革",而且这种变革几乎让所有人都感觉非常舒服,自然而然的就完成了这样的一个变化.最根本的原因其实是大数据技术的应用真正帮助我们解决了问题.我想也正是基于大数据技术的超强实用性吧,它才会被上升到国家战略层面的高度得以出现在政府工作报告中.大数据技术的应用于,对于建设智慧政务平台的可谓功不可没.智慧政务云平台的建设技术以及方案,可以说是比较成熟了,当然前提是必须与大的.开发团队强的大数

JAVA学习篇--javaweb之Filter详解

在DRP项目中,多次提到了Filter,它解决了字符集的统一设置以及统一控制简单WebCache,从中我们可以体会到,它给我们带来的好处不仅仅是减少代码量这么简单,它的出现避免了我们每个页面重复的编写相同的代码,减少了我们的工作量,而且给维护带来了极大的便利,那么它是如何实现统一管理的呢?既然它能统一管理某些重复的操作,那么它和AOP有什么关系呢? Filter简介 ServletAPI中提供了一个Filter接口,开发web应用时,如果编写的Java类实现了这个接口,则把这个java类称之为过