SSH简单项目实例(附下载)
来源:互联网 发布:源码商城 编辑:程序博客网 时间:2024/05/21 17:06
一个简单的SSH项目框架,基本配置,增删改查,分页都有,jar包在WEB-INF下的lib下面,可以直接运行。
1.项目环境
myeclipse10JDK1.7Tocat7.0Spring3.2.5Struts2.3.24Hibernate3.0Mysql5.5
2.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: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/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <!-- 引入外部属性文件 --> <context:property-placeholder location="classpath:jdbc.properties" /> <!-- 配置连接池 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${jdbc.driverClass}"></property> <property name="jdbcUrl" value="${jdbc.url}"></property> <property name="user" value="${jdbc.username}"></property> <property name="password" value="${jdbc.password}"></property> </bean> <!-- 配置hibernate的相关属性 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <!-- 配置hibernate属性 --> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop><!-- 有表自动更新表结构,没有就创建表 --> </props> </property> <!-- 配置关联关系映射文件 --> <property name="mappingResources"> <list> <value>com/entity/Department.hbm.xml</value> <value>com/entity/Employee.hbm.xml</value> <value>com/entity/User.hbm.xml</value> </list> </property> </bean> <!-- 配置action,action交由spring管理 --> <bean id="employeeAction" class="com.action.EmployeeAction" scope="prototype"> <property name="employeeService" ref="employeeService"></property> <property name="departmentService" ref="departmentService"></property> </bean> <bean id="departmentAction" class="com.action.DepartmentAction" scope="prototype"> <property name="departmentService" ref="departmentService"></property> </bean> <bean id="userAction" class="com.action.UserAction" scope="prototype"> </bean> <!-- 配置业务层service --> <bean id="employeeService" class="com.service.impl.EmployeeServiceImpl"> <property name="employeeDao" ref="employeeDao"></property> </bean> <bean id="departmentService" class="com.service.impl.DepartmentServiceImpl"> <property name="departmentDao" ref="departmentDao"></property> </bean> <!-- 配置dao --> <bean id="employeeDao" class="com.dao.impl.EmployeeDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="departmentDao" class="com.dao.impl.DepartmentDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- 开启注解事务 --> <tx:annotation-driven transaction-manager="transactionManager" /></beans>
update,配置好表对应的hbm.xml,项目运行的时候直接生成数据库。
3.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="default" extends="struts-default" namespace="/"> <action name="user_*" class="userAction" method="{1}" > <result name="INPUT">/index.jsp</result> <result name="SUCCESS" type="redirect" >/frame.jsp</result> <result name="HOME" >/frame/right.jsp</result> </action> <action name="employee_*" class="employeeAction" method="{1}" > <result name="INPUT">/index.jsp</result> <result name="SUCCESS" type="redirect" >/frame.jsp</result> <result name="findAll">/jsp/employee/listEmployee.jsp</result> <result name="goAddEmployee">/jsp/employee/addEmployee.jsp</result> <result name="addSuccess" type="redirect">employee_findAll.action</result> <result name="goEditEmployee">/jsp/employee/editEmployee.jsp</result> <result name="editSuccess" type="redirect">employee_findAll.action</result> <result name="deleteSuccess" type="redirect">employee_findAll.action</result> </action> <action name="department_*" class="departmentAction" method="{1}"> <result name="findAll">/jsp/department/listDepartment.jsp</result> <result name="goAddDepartment">/jsp/department/addDepartment.jsp</result> <result name="addSuccess" type="redirect">department_findAll.action</result> <result name="goEditDepartment">/jsp/department/editDepartment.jsp</result> <result name="updateSuccess" type="redirect">department_findAll.action</result> <result name="deleteSuccess" type="redirect">department_findAll.action</result> </action> </package></struts>
4.web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>skyLine</display-name> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> <init-param> <param-name>flushMode</param-name> <param-value>AUTO</param-value> </init-param> </filter> <filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping> <filter> <filter-name>struts</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list></web-app>
5.项目结构
6.运行
项目比较简单,直接可以运行,因为只是一个简单基础框架,直接附上下载地址:
阅读全文
0 0
- SSH简单项目实例(附下载)
- 【SSH网上商城项目实战30】项目总结(附源码下载地址)
- 【SSH网上商城项目实战30】项目总结(附源码下载地址)
- 【SSH网上商城项目实战30】项目总结(附源码下载地址)
- 【SSH网上商城项目实战30】项目总结(附源码下载地址)
- jQuery.ajax的简单应用实例 附实例下载
- jQuery.ajax的简单应用实例 附实例下载
- BizTalk 2006 简单入门示例程序 Version 2.0(附源项目文件下载)
- java浏览器文件下载实例(附源码下载地址)
- SSH项目搭建图文流程,附整合jar包下载地址
- 简单三步,教你如何将Xutils3导入eclipse项目当中(附jar包下载地址)
- Base64编码解码(附运行实例下载)
- CKEditor+CKFinder的jsp实例(附下载包)
- SSH整合(一)Struts简单实例
- SSH 简单实例图
- mysql+ssh整合例子,附源码下载
- SimpleCursorAdapter简单实例(附源码)
- Android调用JNI的简单实例(附详细步骤)
- 台湾大学林轩田机器学习技法课程学习笔记5 -- Kernel Logistic Regression
- OC-集合类(数组)
- JavaScript重构(三):JavaScript的测试
- Redis的基本数据类型
- JavaScript重构(二):JS的动态加载
- SSH简单项目实例(附下载)
- 背包问题解析
- JS-RegExp正则表达式的对象
- JavaScript重构(一):模块划分和命名空间
- Java.lang.StringBuilder常用类
- Scala练习-插值查找
- JavaScript重构(九):自定义的JavaScript产品框架
- SQL Server 表变量和临时表的区别
- mysleep与竞态条件下的mysleep