Spring-Blog:个人博客(一)-Mybatis 读写分离

  2018,在平(tou)静(lan)了一段时间后,开始找点事情来做。这一次准备开发一个个人博客,在开发过程之中完善一下自己的技术。本系列博客只会提出一些比较有价值的技术思路,不会像写流水账一样记录开发过程。

  技术栈方面,会采用Spring Boot 2.0 作为底层框架,主要为了后续能够接入Spring Cloud 进行学习拓展。并且Spring Boot 2.0基于Spring5,也可以提前预习一些Spring5的新特性。后续技术会在相应博客中提出。

  项目GitHub地址:https://github.com/jaycekon/SpringBoot

  介绍一下目录结构:

Spring-Blog( Parent 项目)

Spring-Blog-common( Util 模块)

Spring-Blog-business(Repository模块)

Spring-Blog-api (Web 模块)

Spring-Blog-webflux (基于Spring Boot 2.0Web模块)

 

  为了让各位朋友能够更好理解这一模块的内容,演示代码将存放在Spring Boot 项目下:

  Github 地址:https://github.com/jaycekon/SpringBoot

  1、DataSource

    在开始讲解前,我们需要先构建后我们的运行环境。Spring Boot 引入 Mybatis 的教程 可以参考 传送门 。这里我们不细述了,首先来看一下我们的目录结构:

Spring-Blog:个人博客(一)-Mybatis 读写分离

 

  有使用过Spring Boot 的童鞋应该清楚,当我们在application.properties 配置好了我们的数据库连接信息后,Spring Boot 将会帮我们自动装载好 DataSource 。但如果我们需要进行读写分离操作是,如何配置自己的数据源,是我们必须掌握的。

  首先我们来看一下配置文件中的信息:

spring.datasource.url=jdbc:mysql://localhost:3306/charles_blog2 spring.datasource.username=root spring.datasource.password=root spring.datasource.driver-class-name=com.mysql.jdbc.Driver #别名扫描目录 mybatis.type-aliases-package=com.jaycekon.demo.model #Mapper.xml扫描目录 mybatis.mapper-locations=classpath:mybatis-mappers/*.xml #tkmapper 帮助工具 mapper.mappers=com.jaycekon.demo.MyMapper mapper.not-empty=false mapper.identity=MYSQL

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpdzjs.html