Chinaunix首页 | 论坛 | 博客
  • 博客访问: 495027
  • 博文数量: 96
  • 博客积分: 6046
  • 博客等级: 准将
  • 技术积分: 908
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-07 22:40
文章分类

全部博文(96)

文章存档

2009年(12)

2008年(18)

2007年(45)

2006年(21)

我的朋友

分类: Java

2008-12-01 20:55:24

Struts 2 + Spring 2.0 + Hibernate 3.0整合的操作可以参照我的这篇文章



本文提供Struts2整合Spring Hibernate的CRUD的实例的源代码

1. 数据库脚本,数据库采用MySQL 5.0

CREATE TABLE `user` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(32) NOT NULL,
`password` varchar(32) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

2. 几个重要的文件

web.xml


xmlns:xsi="[url=][/url]"
xsi:schemaLocation="[url=][/url]
[url=/web-app_2_5.xsd]/web-app_2_5.xsd[/url]">


  contextConfigLocation
  /WEB-INF/applicationContext*.xml



  struts2
  
   org.apache.struts2.dispatcher.FilterDispatcher
  



  struts2
  /*



  
   org.springframework.web.context.ContextLoaderListener
  




  lazyLoadingFilter
  
   org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
  



  lazyLoadingFilter
  *.action


  /user/userAdd.jsp

applicationContext.xml


xmlns:xsi="[url=][/url]"
xsi:schemaLocation="[url=][/url] [url=/spring-beans-2.0.xsd]/spring-beans-2.0.xsd[/url]">

  class="org.apache.commons.dbcp.BasicDataSource">
     value="com.mysql.jdbc.Driver">
  

     value="jdbc:mysql://localhost:3306/catalog">
  

  
  

  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  
   
  

  
   
   
     org.hibernate.dialect.MySQLDialect
   

   

  

  
   
    org/ethip/catalog/model/User.hbm.xml
   

  



  
   
  


  class="org.ethip.catalog.service.UserService">
  
   
  


  scope="prototype">
  
   
  


  scope="prototype">
  
   
  


  scope="prototype">
  
   
  


  scope="prototype">
  
   
  


  scope="prototype">
  
   
  


struts.xml










  
   userList.action
  

  
   /user/userList.jsp
  

     method="userDelete">
   userList.action
  

     method="userEdit">
   /user/userEdit.jsp
  

     method="userUpdate">
   userList.action
  



3. 本实例仅实现CRUD功能,没有实现其他的处理,如数据校验、国际化、分页等.

4. 由于附件过大,lib下所有的jar都删掉了,请各位学习者按照上一文的操作导入。

附件是ssh2目录结构

阅读(692) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~