您的位置:首页 > 编程语言 > Python开发

python爬虫学习三:python正则表达式

2015-11-10 15:38 756 查看
* 本框架也是一个很简单的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了。

待续。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: