python爬虫学习三:python正则表达式
2015-11-10 15:38
756 查看
* 本框架也是一个很简单的SSH2框架,只是希望在DAO层中能够支持hibernate的对象操作和jdbc的sql查询而写的一个简单例子框架。所以本框架注重DAO层的代码。
一。通过spring配置hibernate和jdbc的支持:
spring配置文件:
这样我们的项目中就可以使用hibernate的同时又支持jdbc。hibernate只要做增,删,改操作和一些HQL查询。jdbc帮助我们完成一些复杂的查询语句。
二。使用hibernate和jdbc
新增一个Persistence类将hibernateTemplate和jdbcTemplate注入到该类中。
这样我们的持久类就支持hibernate和jdbc了。
待续。。。
一。通过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了。
待续。。。
相关文章推荐
- python爬虫学习二: urllib2模块的学习
- Openstack python api 学习文档 api创建虚拟机
- python去除停用词(结巴分词下)
- python列表和元组
- Python核心数据类型——字符串(1)
- [Python]小笔记-queue
- [Machine Learning]Numpy
- python基础9之IO
- Python 3读写文件和Python2的区别
- python and C
- Python——动态数据类型
- Python Selenium 键盘和鼠标操作
- [LeetCode]题解(python):045-Jump Game II
- Python核心数据类型——布尔型
- Python核心数据类型——集合(Set)
- (转)Python 字典排序
- python数据分析实战之泰坦尼克号统计
- Python 定时执行线程 执行任务
- python控制台中实现进度条功能
- python学习问题之-编码