- 浏览: 1238593 次
- 性别:
- 来自: 杭州
文章分类
- 全部博客 (193)
- ant/maven (6)
- algorithm (5)
- tomcat/weblogic/jboss (6)
- javascript/jquery (13)
- java (33)
- flex/flash (0)
- JPA/Hibernate/myBatis (18)
- java concurrent (7)
- test (2)
- windows/linux (6)
- java collection (7)
- design pattern (2)
- life/health (3)
- database (12)
- IDE (4)
- spring/ejb (20)
- html/css/ckeditor (7)
- jsp/servlet (3)
- java io (13)
- java security (4)
- jni (0)
- svn/git (2)
- english (2)
- java jmx (1)
- xml (1)
- struts/springmvc (9)
- middleware (2)
- cache (1)
- cglib (3)
最新评论
-
jlotusYo:
博主,真感谢。
Java 密码扩展无限制权限策略文件 -
senninha:
这个。。是api说明吧。。
ScheduledExecutorService 源码分析 -
zoutao2008:
请问大文件如何处理?按你这种方式的话,文件超过200M时就会报 ...
hessian系列之二:上传文件 -
lwj1113:
lwj1113 写道谢谢博主这么细致的demo;在系列五中通过 ...
myBatis系列之五:与Spring3集成 -
lwj1113:
谢谢博主这么细致的demo;在系列五中通过testng测试类跑 ...
myBatis系列之五:与Spring3集成
一. spring JPA struts 整合开发(1) - spring集成JPA
二. spring JPA struts 整合开发(2) - spring集成struts
这里的JPA实现是hibernate。
1. 在IDE中新建一个web工程,Resource设置成utf-8
2. 导入以下的jar包到/WEB-INF/lib目录下:
Hibernate 3安装包下的:
hibernate3.jar
lib\required\*.jar
lib\test\slf4j-log4j12.jar
spring 2.5 安装包下的:
dist\spring.jar
dist\modules\spring-webmvc-struts.jar
lib\jakarta-commons\common-logging.jar commons-dbcp.jar commons-pool.jar
lib\aspectj\aspectjweaver.jar aspectjrt.jar
lib\cglib\cglib-nodep-2.1_3.jar
lib\j2ee\common-annotations.jar
lib\log4j\log4j-1.2.15.jar
下载struts-1.3.8-lib.zip,解压目录下的所有jar
3. spring配置文件:
拷贝一个beans.xml的模板到src目录下,
beans.xml内容:
4. JPA配置文件
在src目录下创建META-INF子目录并新建persistence.xml文件:
5. 实体bean
创建com.john.bean.Person类
6. 业务bean
创建com.john.service.PersonServiceBean类
抽取PersonService接口。
7. junit test
新建junit.test.PersonServiceTest测试类:
整理自:传智播客spring教程
二. spring JPA struts 整合开发(2) - spring集成struts
这里的JPA实现是hibernate。
1. 在IDE中新建一个web工程,Resource设置成utf-8
2. 导入以下的jar包到/WEB-INF/lib目录下:
Hibernate 3安装包下的:
hibernate3.jar
lib\required\*.jar
lib\test\slf4j-log4j12.jar
spring 2.5 安装包下的:
dist\spring.jar
dist\modules\spring-webmvc-struts.jar
lib\jakarta-commons\common-logging.jar commons-dbcp.jar commons-pool.jar
lib\aspectj\aspectjweaver.jar aspectjrt.jar
lib\cglib\cglib-nodep-2.1_3.jar
lib\j2ee\common-annotations.jar
lib\log4j\log4j-1.2.15.jar
下载struts-1.3.8-lib.zip,解压目录下的所有jar
3. spring配置文件:
拷贝一个beans.xml的模板到src目录下,
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:context="http://www.springframework.org/schema/context" 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.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd" > <context:annotation-config/> <!-- JPA entity manager factory bean, like the session factory of hibernate --> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"> <!-- Retrieved the persistence information from persistence.xml --> <property name="persistenceUnitName" value="sparkle" /> </bean> <!-- Transaction manager --> <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <tx:annotation-driven transaction-manager="txManager"/> </beans>
4. JPA配置文件
在src目录下创建META-INF子目录并新建persistence.xml文件:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0"> <persistence-unit name="sparkle" transaction-type="RESOURCE_LOCAL"> <properties> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8"/> <property name="hibernate.connection.username" value="root"/> <property name="hibernate.connection.password" value="123456"/> <property name="hibernate.max_fetch_depth" value="3"/> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="hibernate.show_sql" value="true"/> </properties> </persistence-unit> </persistence>
5. 实体bean
创建com.john.bean.Person类
// It is recommended to let the bean implement Serializable interface and override equals and hashCode methods @Entity public class Person implements { private Integer id; private String name; public Person() { } public Person(String name) { this.name = name; } @Id @GeneratedValue public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } @Column(length=30, nullable=false) public String getName() { return name; } public void setName(String name) { this.name = name; } }
6. 业务bean
创建com.john.service.PersonServiceBean类
@Transactional public class PersonSeriveBean { @PersistenceContext EntityManager em; public void save(Person person) { em.persist(person); } public void update(Person person) { em.merge(person); } public void delete(Integer id) { em.remove(em.getReference(Person.class, id)); } @Transactional(propagation=Propagation.NOT_SUPPORTED, readOnly=true) public Person getPerson(Integer id) { return em.find(Person.class, id); } @Override @Transactional(propagation=Propagation.NOT_SUPPORTED, readOnly=true) public List<Person> getPersons() { return em.createQuery("select p FROM Person p").getResultList(); }
抽取PersonService接口。
7. junit test
新建junit.test.PersonServiceTest测试类:
public class PersonServiceTest { private static PersonService personService; @BeforeClass public static void setUpBeforeClass() throws Exception { try { AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml"); personService = (PersonService)ctx.getBean("personService"); } catch (Exception e) { e.printStackTrace(); } } @Test public void testSave() { personService.save(new Person("John")); } // Other test methods are omitted }
整理自:传智播客spring教程
发表评论
-
本地事务系列之五:使用Transactional注解
2014-08-02 18:16 2785AOP的配置稍显复杂,通过@Transactional注解,同 ... -
本地事务系列之四:使用AOP
2014-08-02 17:08 868Spring AOP通过在文件中配置来管理事务,好处是对代码侵 ... -
本地事务系列之三:使用TransactionTemplate
2014-07-17 22:15 6694TransactionTemplate的灵活性好,可以给代码块 ... -
本地事务系列之二:使用PlatformTransactionManager
2014-07-17 21:37 5339Spring的事务管理器接口: public interf ... -
本地事务系列之一:JDBC操作
2014-07-08 23:04 1207本地事务即对一个数据源进行操作。大多数数据库支持事务。 先看 ... -
Spring AOP 源码系列:ProxyFactoryBean
2014-04-21 18:01 0public class ProxyFactoryBean ... -
Spring AOP 源码系列
2014-04-21 09:22 0Spring AOP通过JDK的正则表达式对Pointcut表 ... -
Spring AOP系列之五:后置通知
2014-04-14 08:59 1636和前置通知类似, 通过实现org.springframewor ... -
Spring AOP系列之四:前置通知
2014-04-13 21:28 1794通过实现org.springframework.aop.M ... -
Spring AOP系列之三:环绕代理
2014-04-13 18:20 1386通过实现org.aopalliance.intercept.M ... -
Spring AOP系列之二:Java代理
2014-04-13 18:00 1020通过Java代理的方式: 汽车的代理,需要实现java.la ... -
Spring AOP系列之一:手动方式
2014-04-13 17:44 1357AOP (Aspect Oriented Progra ... -
HibernateTemplate 使用
2014-03-03 22:09 01. queryListBySql hibernateTe ... -
Spring的组件扫描
2017-09-16 21:58 1028Spring2.0以后的版本中,引入了基于注解(Annotat ... -
ContextLoaderListener和ContextCleanupListener源码分析
2013-12-18 15:55 0public class ContextLoaderLis ... -
Cglib2AopProxy 源码分析
2013-12-05 14:30 0final class Cglib2AopProxy im ... -
Spring生命周期方法的调用顺序
2013-11-19 22:04 0Spring的几个接口: BeanFactoryAware: ... -
一、Spring AOP的简单实例
2013-11-06 23:31 17361. 往pom.xml文件添加以下依赖: <depe ... -
Spring配置中的bean引用其它bean的属性值
2013-01-23 15:24 4185这项功能在spring的3.0版本以上才支持,如果使用较早的版 ... -
spring JPA struts 整合开发(2) - spring集成struts
2012-05-20 20:55 1389一. spring JPA struts 整合开发(1) - ...
相关推荐
JPA+Spring+Struts整合实例,JPA+Spring+Struts整合实例
NULL 博文链接:https://pihai.iteye.com/blog/403437
spring struts2 JPAspring struts2 JPAspring struts2 JPAspring struts2 JPA
struts2_spring_jpa整合实例实现数据添加
struts jpa spring 整合 源代码
没事了做一个demo 玩玩想学习的可以看一下。这是个初步的整合。里面什么功能都没有。有一个登录和filter 本人是做BI的 以后会把BI整合进去,同时也把权限也整合进去。
在学习jpa时候做的一个struts2+spring+jpa整合的完整例子 包含分页,一个简单的 资产入库系统 并实现了登陆等。
struts2+jpa+spring的详细整合,PPT上面有详细解说
JPA+Spring+Struts整合实例 Spring2.x Struts1.x 该实例没有包含lib包,自己导入就可以了,如果用的myeclipse 那就更好了 该例子有个说明文件,一定要看
Spring+Struts2+JPA入门小例子
Struts2,spring2.5与jpa的整合,包括精确到领域对象的权限管理
关于spring+Struts2+jpa集成 小列子
spring3.1 struts2.3 hibernate4.1 jpa集成小例子,实现查询和添加小功能,删除和修改同理自己写吧。
Jpa+Spring+Struts集成步骤详解
hibernate(jpa) spring2.5.6 struts2.1.8整合开发需要的所有jar包包括tiles框架的jar包
struts2 spring jpa整合案例 可以直接导入到myeclipse中运行
很简单的,只是搭建了平台,可以作为blank使用
JPA STRUTS SPRING EXTJS JSON
1.1.24-20120814.043343-7.jar freemarker-2.3.19.jar hibernate-commons-annotations-4.0.1.Final.jar hibernate-core-4.2.1.Final.jar hibernate-jpa-2.0-api-1.0.1.Final.jar hibernate-validator-5.1.0.Final....
使用Struts2.2.3+Spring3.0.5+JPA2.0框架案例。 包含包。使用eclipse导入,直接可以运行。编码使用GBK。 出现乱码的话,把默认编码改为GBK就OK了。