applicationContext-common.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: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-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution(* org.myclover.user.service.impl.*.*(..))"/>
<aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/>
</aop:config>
</beans>
applicationContext-beans.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: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-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="userManager" class="org.myclover.user.service.impl.UserManagerImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</beans>
CRUD的操作代码
package org.myclover.user.test;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import junit.framework.TestCase;
import org.myclover.user.User;
import org.myclover.user.service.UserManager;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestUser extends TestCase {
public void testAddUser() {
User user = null;
BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext-*.xml");
UserManager userManager = (UserManager)factory.getBean("userManager");
try {
user = new User();
user.setUserName("蔡依林");
user.setUserSex("女");
user.setUserEmail("cyl@126.com");
user.setUserBirthday(new Date());
userManager.addUser(user);
} catch (Exception e) {
e.printStackTrace();
}
}
public void testFindUser() {
User user = null;
BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext-*.xml");
UserManager userManager = (UserManager)factory.getBean("userManager");
try {
user = new User();
user = userManager.findById(2);
System.out.println("userName= " + user.getUserName());
System.out.println("userSex= " + user.getUserSex());
System.out.println("userEmail= " + user.getUserEmail());
System.out.println("userBirthday= " + user.getUserBirthday());
} catch (Exception e) {
e.printStackTrace();
}
}
public void testGetAllUser() {
User user = null;
BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext-*.xml");
UserManager userManager = (UserManager)factory.getBean("userManager");
try {
user = new User();
List list = userManager.getAllUser();
for(Iterator iterator = list.iterator();iterator.hasNext();){
user = (User)iterator.next();
System.out.println("userName= " + user.getUserName());
System.out.println("userSex= " + user.getUserSex());
System.out.println("userEmail= " + user.getUserEmail());
System.out.println("userBirthday= " + user.getUserBirthday());
System.out.println("===========================================");
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void testDeleteUser() {
BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext-*.xml");
UserManager userManager = (UserManager)factory.getBean("userManager");
try {
userManager.deleteUser(6);
} catch (Exception e) {
e.printStackTrace();
}
}
public void testUpdateUser() {
User user = null;
BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext-*.xml");
UserManager userManager = (UserManager)factory.getBean("userManager");
try {
user = new User();
user.setUserId(1);
user.setUserName("贾静雯");
user.setUserSex("女");
user.setUserEmail("jjw@163.com");
user.setUserBirthday(new Date());
userManager.updateUser(user);
} catch (Exception e) {
e.printStackTrace();
}
}
}
分享到:
相关推荐
struts2 spring 2.5 hibernate3整合 CRUD实例含分页 整合版本struts2 spring 2.5 hibernate3 简单的实现了一个用户的CRUD操作(列表展示有分页版本) 设计到了Validate效验,excel生成下载
Struts2整合Spring Hibernate的CRUD实例Struts2整合Spring Hibernate的CRUD实例
整合版本struts2 spring 2.5 hibernate3 简单的实现了一个用户的CRUD操作 设计到了Validate效验,excel生成下载 不建议下载,这是我自己写的一个测试代码,为以后查资料用的
现在就将笔者使用Myeclipse工具应用struts2 + spring2 + hibernate3 实现CRUD操作的步骤一一纪录下来,为初学者少走弯路略尽绵薄之力!在本文中,笔者将Struts2.0.6、Spring2.0.6和Hibernate3.1进行整合,希望通过...
用EXT+struts2+spring+hibernate做的一个增删改查实例,主要用到了EXTjs里面的部分组件,用JSON与服务端交互,实现一个增删改查的功能!本地MYsql数据库,sql文件在根目录下面,建好库既可以运行!当然,还是需要在...
部门人员一对多的CRUD操作 hibernate: 管理实体关系映射 spring:数据源配置与获得session IOC依赖注入 和 AOP 事务管理 jsf : backing bean的操作 jsf 标签应用 jsf 信息国际化以资源绑定 jsf 表单验证 jsf ...
Spring提供了org.springframework.orm.hibernate3.HibernateTemplate类和org.springframework.orm.hibernate3.HibernateCallback接口来方便和Hibernate整合。 HibernateTemplate类封装了Hibernate的主要类,它提供了...
ext的一个增删改查的例子,用的是Hibernate+Spring+Struts2
spring-hibernate-dwr做的AJAX操作CRUD实例 环境:myeclipse6.0+jdk1.6 所需lib列表,请自行加入 mysql-connector-java-3.1.7-bin.jar antlr-2.7.6rc1.jar asm-attrs.jar cglib-2.1.3.jar ...
①在web.xml中配置ApplicationContext.xml,并使用ContextLoader监听器实例化spring容器 ②把action交给spring管理,即在spring配置文件中定义action Bean并使用依赖注入功能在action中注入业务Bean,同时修改作用域...
springMvc+hibernate4+spring整合实例 包内有对实例的crud 增删查改 分享此资源希望一起学习 若有什么不足之处 可以指出 谢谢
现在就将笔者使用Myeclipse工具应用struts2 + spring2 + hibernate3 实现CRUD操作的步骤一一纪录下来,为初学者少走弯路略尽绵薄之力!在本文中,笔者将Struts2.0.6、Spring2.0.6和Hibernate3.1进行整合,希望通过...
struts + hibernate + spring, 用户登录后,操作-CRUD (连数据库都给出来了!“傻瓜式导入运行”) SSH整合初学者适用,物有所值....
三大框架struts2 hibernate spring 整合的实例项目
Struts2、Hibernate、Spring整合的泛型DAO (本人评价: 代码开发效率提高30% 代码出错率减少70%) 对于大多数开发人员,系统中的每个 DAO 编写几乎相同的代码到目前为止已经成为一种习惯。虽然所有人都将这种重复...
基于spring,struts2,hibernate开发的两个表之间CRUD操作的实例;可供参考!
SSH 为 struts+spring+hibernate的一个集成框架,是目前较流行的一种Web应用程序开源框架。集成SSH框架的系统从职责上分为四层:表示层、业务逻辑层、数据持久层和域模块层,以帮助开发人员在短期内搭建结构清晰、可...
网上有很多关于SSH架构的实例...就是完成一个人员的CRUD操作,麻雀虽小,五脏俱全,希望能对从来没有接触过三者结合开发的朋友带来一点点帮助,这个例子,也算是我的入门实例,从此,开始Struts+Spring+Hibernate之旅
成功移植到ssm(strut2、spring、mybatis)实现了“hibernate和mybatis的之CRUD封装比较”(http://blog.csdn.net/linchengzhi/article/details/7332529)的设计思想。 本资源所需的jar包请到“ssh框架搭建实例源码2...
成功移植到ssm(strut2、spring、mybatis)实现了“hibernate和mybatis的之CRUD封装比较”(http://blog.csdn.net/linchengzhi/article/details/7332529)的设计思想;增加了项目的介绍;可以作为项目开发的基础框架...