Commit 41760925 authored by 宋欢's avatar 宋欢

data-source

parent 60976805
MySQL的操作,离不开Laravel-DB和Model,简单一句话,DB::table('user')->where('id', 1)->first(); MySQL的操作,离不开Laravel-DB和Model,简单一句话,DB::table('user')->where('id', 1)->first();
Java也有类似Laravel-DB的ORM框架,之前流行Hibernate,现在我们用MyBatis Java也有类似Laravel-DB的ORM框架,之前流行Hibernate,现在我们用MyBatis
配置
...@@ -23,7 +23,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; ...@@ -23,7 +23,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableTransactionManagement @EnableTransactionManagement
@EnableScheduling @EnableScheduling
@ComponentScan(basePackages = {"cn.qmai.study.java.demo"}) @ComponentScan(basePackages = {"cn.qmai.study.java.demo"})
@ImportResource(locations = {"classpath:data-sharing.xml"}) @ImportResource(locations = {"classpath:data-source.xml"})
@EnableSwagger2 @EnableSwagger2
public class Application { public class Application {
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
</bean> </bean>
<!-- 配置,连接、用户名、密码 --> <!-- 配置,连接、用户名、密码 -->
<bean id="dataSynDs" parent="abstractDataSource" primary="false"> <bean id="dataSource" parent="abstractDataSource" primary="false">
<property name="url" <property name="url"
value="jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf-8&amp;useSSL=false&amp;serverTimezone=Asia/Shanghai&amp;allowMultiQueries=true"/> value="jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf-8&amp;useSSL=false&amp;serverTimezone=Asia/Shanghai&amp;allowMultiQueries=true"/>
<property name="username" value="root"/> <property name="username" value="root"/>
...@@ -50,8 +50,8 @@ ...@@ -50,8 +50,8 @@
</bean> </bean>
<!-- Mybatis 配置 --> <!-- Mybatis 配置 -->
<bean id="dataSynMybatis" class="org.mybatis.spring.SqlSessionFactoryBean"> <bean id="dataSourceMybatis" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSynDs"/> <property name="dataSource" ref="dataSource"/>
<property name="typeAliasesPackage" value="cn.qmai.study.java.demo.biz.model"/> <property name="typeAliasesPackage" value="cn.qmai.study.java.demo.biz.model"/>
<property name="mapperLocations" value="classpath:/mappings/*.xml"/> <property name="mapperLocations" value="classpath:/mappings/*.xml"/>
<property name="configLocation" value="classpath:/mybatis.xml"/> <property name="configLocation" value="classpath:/mybatis.xml"/>
...@@ -59,13 +59,13 @@ ...@@ -59,13 +59,13 @@
</bean> </bean>
<!-- Mybatis 接口扫描 --> <!-- Mybatis 接口扫描 -->
<bean id="dataSynScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <bean id="dataSourceScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="dataSynMybatis"/> <property name="sqlSessionFactoryBeanName" value="dataSourceMybatis"/>
<property name="basePackage" value="cn.qmai.study.java.demo.biz.dao"/> <property name="basePackage" value="cn.qmai.study.java.demo.biz.dao"/>
</bean> </bean>
<!-- 定义事务 --> <!-- 定义事务 -->
<bean id="dataSynTransaction" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <bean id="dataSourceTransaction" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSynDs"/> <property name="dataSource" ref="dataSource"/>
</bean> </bean>
</beans> </beans>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment