Commit 41760925 authored by 宋欢's avatar 宋欢

data-source

parent 60976805
MySQL的操作,离不开Laravel-DB和Model,简单一句话,DB::table('user')->where('id', 1)->first();
Java也有类似Laravel-DB的ORM框架,之前流行Hibernate,现在我们用MyBatis
配置
......@@ -23,7 +23,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableTransactionManagement
@EnableScheduling
@ComponentScan(basePackages = {"cn.qmai.study.java.demo"})
@ImportResource(locations = {"classpath:data-sharing.xml"})
@ImportResource(locations = {"classpath:data-source.xml"})
@EnableSwagger2
public class Application {
......
......@@ -41,7 +41,7 @@
</bean>
<!-- 配置,连接、用户名、密码 -->
<bean id="dataSynDs" parent="abstractDataSource" primary="false">
<bean id="dataSource" parent="abstractDataSource" primary="false">
<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"/>
<property name="username" value="root"/>
......@@ -50,8 +50,8 @@
</bean>
<!-- Mybatis 配置 -->
<bean id="dataSynMybatis" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSynDs"/>
<bean id="dataSourceMybatis" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="typeAliasesPackage" value="cn.qmai.study.java.demo.biz.model"/>
<property name="mapperLocations" value="classpath:/mappings/*.xml"/>
<property name="configLocation" value="classpath:/mybatis.xml"/>
......@@ -59,13 +59,13 @@
</bean>
<!-- Mybatis 接口扫描 -->
<bean id="dataSynScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="dataSynMybatis"/>
<bean id="dataSourceScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="dataSourceMybatis"/>
<property name="basePackage" value="cn.qmai.study.java.demo.biz.dao"/>
</bean>
<!-- 定义事务 -->
<bean id="dataSynTransaction" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSynDs"/>
<bean id="dataSourceTransaction" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
</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