* 本框架也是一个很简单的SSH2框架,只是希望在DAO层中能够支持hibernate的对象操作和jdbc的sql查询而写的一个简单例子框架。所以本框架注重DAO层的代码。
一。通过spring配置hibernate和jdbc的支持:
spring配置文件:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- 配置数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="jdbcUrl">
<value>jdbc:mysql://127.0.0.1:3306/lh446?useUnicode=true&characterEncoding=utf-8</value>
</property>
<property name="user">
<value>root</value>
</property>
<property name="password">
<value>lh446</value>
</property>
<property name="minPoolSize">
<value>1</value>
</property>
<property name="maxPoolSize">
<value>20</value>
</property>
<property name="maxIdleTime">
<value>1800</value>
</property>
<property name="acquireIncrement">
<value>2</value>
</property>
<property name="maxStatements">
<value>0</value>
</property>
<property name="initialPoolSize">
<value>2</value>
</property>
<property name="idleConnectionTestPeriod">
<value>1800</value>
</property>
<property name="acquireRetryAttempts">
<value>30</value>
</property>
<property name="breakAfterAcquireFailure">
<value>false</value>
</property>
</bean>
<!-- 配置Hibernate -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>com/lh446/authority/entity/Functionn.hbm.xml</value>
<value>com/lh446/authority/entity/Role.hbm.xml</value>
<value>com/lh446/authority/entity/Users.hbm.xml</value>
<value>com/lh446/authority/entity/UserRole.hbm.xml</value>
<value>com/lh446/authority/entity/RoleFunction.hbm.xml</value>
<value>com/lh446/authority/entity/Code.hbm.xml</value>
<value>com/lh446/authority/entity/SysLog.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.connection.release_mode">auto</prop>
<prop key="hibernate.autoReconnect">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
</props>
</property>
</bean>
<!-- 配置hibernate -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 配置jdbc -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
这样我们的项目中就可以使用hibernate的同时又支持jdbc。hibernate只要做增,删,改操作和一些HQL查询。jdbc帮助我们完成一些复杂的查询语句。
二。使用hibernate和jdbc
新增一个Persistence类将hibernateTemplate和jdbcTemplate注入到该类中。
public class Persistence {
private JdbcTemplate jdbcTemplate;
private HibernateTemplate hibernateTemplate;
public JdbcTemplate getJdbcTemplate() {
return jdbcTemplate;
}
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public HibernateTemplate getHibernateTemplate() {
return hibernateTemplate;
}
public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}
....
}
这样我们的持久类就支持hibernate和jdbc了。
待续。。。
分享到:
相关推荐
spring mvc + spring + hibernate 全注解整合开发视频教程 11
spring 3.2.0+hibernate 4.1.6+struts2整合需要的jar包 的目录 antlr-2.7.7.jar aopalliance-1.0.jar asm-3.3.jar asm-commons-3.3.jar aspectjweaver-1.5.3.jar bonecp-0.7.1.RELEASE.jar cglib-2.1.3.jar ...
有关Struts2+Spring+Hibernate和Struts2+Spring+Ibatis的整合实例demo 原创,完全基于eclipse开发
整合使用最新版本的三大框架(即Struts2、Spring4和Hibernate4),搭建项目架构原型。 项目架构原型:Struts2.3.20 + Spring4.1.6 + Hibernate4.3.9。 此外,还有:log4j、slf4j、junit4、ehcache等知识点。 项目...
MyEclipse8.0中自带的struts2版本是2.1.6,spring版本有2.0,2.5的,hibernate版本较多些至3.2,首先选版本就选择最优的,struts2没的选只有2.1.6版的,所以先导入struts2支持,然后是spring选的是2.0,问题就出在...
在《开发者突击:Java Web主流框架整合开发(J2EE+Struts+Hibernate+Spring)》架构讲解的过程中,穿插介绍了JDBC、Log4j、Sitemesh、JUnit技术。 随书附赠光盘内容包括《开发者突击:Java Web主流框架整合开发(J2EE+...
系统后端基于SpringMVC+Spring+Hibernate框架,前端页面采用JQuery+Bootstrap等主流技术; 流程引擎基于Snaker工作流;表单设计器基于雷劈网WEB表单设计器。 系统主要功能有: >1.系统管理 >>系统管理包含有:基础...
这是本人上课过程中为学生讲解hibernate、spring和mysql开发简单项目的截图汇集,大家需要先自己完成数据库以及JDBC数据源的配置,之后按照该截图的顺序就能完成一个最简单的支持数据库事务处理的SH系统,(如果使用...
Spring 2.5 jar 所有开发包及完整文档及项目开发实例 spring jar 包详解spring.jar是包含有完整发布的单个jar包,spring.jar中包含除了 spring-mock.jar里所包含的内容外其它所有jar包的内容,因为只有在开发环境下...
Struts 是一个很好的MVC框架,主要技术是Servlet和Jsp。Struts的MVC设计模式可以使我们的逻辑变得很清晰,让我们写的程序层次分明。Spring 提供了管理业务对象的一致方法,并鼓励注入对接口编程而不是对类编程的良好...
12.6.16 编写Spring和Hibernate的配置文件spring-config.xml 12.6.17 编写web.xml 12.6.18 验证示例 12.7 小结 第四篇 J2EE项目案例精选 第十三章 网上调查系统 13.1 系统概述 13.2 需求分析 13.2.1 系统用例图 ...
这是一个Dynamic Web Project,主要使用hibernate和spring框架,其中事务管理使用的是注解。 hibernate的版本:hibernate-distribution-3.6.6.Final; spring的版本:spring-framework-3.1.0.M2 。 注意:此项目没有...
spring-jdbc-3.2.4.RELEASE.jar 整合hibernate: spring-orm-3.2.4.RELEASE.jar 整合web: spring-web-3.2.4.RELEASE.jar 整合Junit测试: spring-test-3.2.4.RELEASE.jar 连接池: c3p0-0.9.5.2.jar
spring+springMVC+mybatis+struts2+jdbc+hibernate 全面集成 此框架本人花费2天时间完成 工作中请勿配置如此多元化框架 框架的意义是为了让代码风格统一 此框架是为了学习 作为参考 jdbc.properties为数据库链接参数...
12.6.16 编写Spring和Hibernate的配置文件spring-config.xml 12.6.17 编写web.xml 12.6.18 验证示例 12.7 小结 第四篇 J2EE项目案例精选 第十三章 网上调查系统 13.1 系统概述 13.2 需求分析 13.2.1 系统用例图 ...
Struts:作为基于 MVC 模式的 Web 应用最...使用 Hibernate 能够节约大量项目开发时间,因为整个 JDBC 层都由这个框架管理。这意味着您的应用程序的数据访问层位于 Hibernate 之上,完全是从底层数据模型中抽象出来的。
(2) spring-beans.jar 这个jar文件是所有应用都要用到的,它包含访问配置文件、创建和管理bean以及进行Inversion of Control / Dependency Injection(IoC/DI)操作相关的所有类。如果应用只需基本的IoC/DI支持,...
sqltoy-orm是比hibernate+myBatis(plus)更加贴合项目的orm框架(依赖spring),具有jpa式的对象CRUD的同时具有比myBatis(plus)更直观简洁性能强大的查询功能。 支持以下数据库: oracle 11g+ db2 9.5+,建议从10.5 开始...
12.6.16 编写Spring和Hibernate的配置文件spring-config.xml 12.6.17 编写web.xml 12.6.18 验证示例 12.7 小结 第四篇 J2EE项目案例精选 第十三章 网上调查系统 13.1 系统概述 13.2 需求分析 13.2.1 系统用例图 ...