Spring+Hibernate+Struts2整合笔记一
来源:互联网 发布:交换机端口隔离命令 编辑:程序博客网 时间:2024/06/14 11:39
一、 Spring+Hibernate整合:
Spring整合Hibernate,是做了一个很大的调整的,因为spring可以把管理Hibernate的工作都做了,以前的hibernate.cfg.xml文件都去掉了,而将这些内容都交给了spring来管理了。
1、 applicationContext.xml文件中应该配置如下内容:
//配置数据连接类
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="org.gjt.mm.mysql.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/test"></property>
<property name="username" value="root"></property>
</bean>
//配置session工厂类
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<value>com/hejianjiao/vo/Person.hbm.xml</value>
</property>
</bean>
2、可以使用spring中的HibernateDAOSupport与HibernateTemplate类来进行数据持久化操作:
A、HibernateDAOSupport类中定义了对session、sessionFactory的操作方法与getHibernateTemplate方法来获得一个HibernateTemplate实例;
B、HibernateTemplate类中定义了对数据持久化的各种封装的方法,我们可以用它来对数据进行操作。
因此在使用时,我们可以继承HibernateDAOSupport类,然后实例化HibernateTemplate类来进行数据持久化。
- Spring+Hibernate+Struts2整合笔记一
- Struts2+Hibernate+Spring整合(一)
- Spring+Hibernate+Struts2整合笔记二
- struts2,hibernate,spring整合笔记(1)
- struts2+hibernate+spring整合
- struts2 spring hibernate 整合
- Spring struts2 hibernate 整合
- struts2+spring+hibernate整合
- struts2+spring+hibernate整合
- struts2+spring+hibernate整合
- Spring、Struts2、Hibernate整合
- Spring + Hibernate + Struts2整合
- struts2+spring+hibernate整合
- struts2+spring+hibernate整合
- Struts2+Hibernate+Spring整合
- Spring Struts2 Hibernate整合
- 整合struts2+spring+hibernate
- spring struts2 hibernate整合
- 如何判断某个控件中的文本是不是数字
- 关于sql登陆的两个错误,服务器错误信息:18452/18456
- 设计模式概览
- Crontab实例
- xp系统sql2005安装问题hotfix.exe 不是有效的 win32 应用程序
- Spring+Hibernate+Struts2整合笔记一
- SQL2005开发版下载地址
- Spring+Hibernate+Struts2整合笔记二
- vs如何删除最近的项目记录
- Spring+Hibernate+Struts2整合文档三
- UI界面设计闪烁问题的解决办法
- .sln文件和.suo文件的解释
- phpcms与discuz!6.1.0整合
- C#常用快捷键