发表于: 2020-10-14 23:03:09
1 1426
今天完成的事情:
遇到的问题:
整合Spring,mybatis,
了解到有四种方法
使用第一种SqlSession
<?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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-5.2.9.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-5.2.9.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-5.2.9.xsd">
<!--表明引用的参数配置文件是mysql-local.properties-->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>
mysql-local.properties
</value>
</list>
</property>
</bean>
<!--数据库连接池-->
<bean id="db" class="db.properties">
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.name}"/>
<property name="password" value="${jdbc.password}"/>
<!-- 初始连接池大小 -->
<property name="initialPoolSize" value="10"/>
<!-- 连接池中连接最小个数 -->
<property name="minPoolSize" value="5"/>
<property name="maxPoolSize" value="20"/>
</bean>
<!-- 配置SqlSessionFactory对象 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 注入数据库连接池 -->
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="mybatis-spring-config.xml"/>
</bean>
<!--<bean id="sqlsessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">-->
<!--<constructor-arg index="0" ref="sqlSessionFactory" />-->
<!--</bean>-->
<!--配置userMapper对象-->
<bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="dao.IUser"/>
<property name="sqlSessionFactory" ref="sqlSessionFactory"/>
</bean>
</beans>
明天计划的事情:
解决BUG中,继续做mybais和Spring整合。
收获:发现mybais和Spring整合后确实会方便很多。
评论