1、实现mybatis-plus的多个数据库的切换方式

源码地址:https://github.com/baomidou/mybatisplus-spring-mvc

2、因为其文档都是相互依赖的,所以修改配置,就是在已有的配置中修改

这里配置多数据源采用定义不同的profile方式修改启动时连接的数据库

原版

配置文件位置:https://github.com/baomidou/mybatisplus-spring-mvc/tree/master/src/main/resources/spring

 <?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:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util"
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.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <!-- 引入属性文件 -->
<context:property-placeholder location="classpath:config.properties"/> <!-- Service包(自动注入) -->
<context:component-scan base-package="com.baomidou.springmvc.service"/> <import resource="classpath:spring/spring-mybatis.xml"/>
</beans>

修改后配置

 <?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:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
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.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd" profile="development"> <!-- 引入属性文件 -->
<!--<context:property-placeholder location="classpath:applicationContext-profile.xml"/>-->
<!--<context:property-placeholder location="classpath:config.properties"/>--> <beans profile="development">
<context:property-placeholder
location="classpath*:common/*.properties,classpath*:development/*.properties"/>
<!-- Service包(自动注入) -->
<!-- 修改了package路径 -->
<context:component-scan base-package="com.rent.springmvc.service"/>
<!--导入mybatis-->
<import resource="classpath:spring/spring-mybatis.xml"/>
</beans> <!-- 测试环境配置文件 -->
<beans profile="test">
<context:property-placeholder
location="classpath*:common/*.properties,classpath*:test/*.properties"/> <!-- Service包(自动注入) -->
<!-- 修改了package路径 -->
<context:component-scan base-package="com.rent.springmvc.service"/>
<!--导入mybatis-->
<import resource="classpath:spring/spring-mybatis.xml"/>
</beans> <!-- 生产环境配置文件 -->
<beans profile="production">
<context:property-placeholder
location="classpath*:common/*.properties,classpath*:production/*.properties"/> <!-- Service包(自动注入) -->
<!-- 修改了package路径 -->
<context:component-scan base-package="com.rent.springmvc.service"/>
<!--导入mybatis-->
<import resource="classpath:spring/spring-mybatis.xml"/>
</beans> </beans>

项目路径截图

development中写修改的

 validationQuery=SELECT 1
###############本地数据库
jdbc_url=jdbc\:mysql\://localhost\:3306/renttest?characterEncoding\=UTF-8
##jdbc_url=jdbc\:mysql\://192.168.31.255\:3306/test?characterEncoding\=UTF-8
jdbc_username=root
jdbc_password=123456

3、beans可以嵌套beans,这是核心配置

<beans profile="development">
<context:property-placeholder
location="classpath*:common/*.properties,classpath*:development/*.properties"/>
<!-- Service包(自动注入) -->
<!-- 修改了package路径 -->
<context:component-scan base-package="com.rent.springmvc.service"/>
<!--导入mybatis-->
<import resource="classpath:spring/spring-mybatis.xml"/> </beans>

import引入其他配置,这是一份拼接的配置文件

MyBatis-Plus 多库部署方式;spring mvc 多库部署方式的更多相关文章

  1. Spring MVC 前后端 Json 方式交互和处理

    众所周知,在mvc中,数据是在各个层次之间进行流转是一个不争的事实. 而这种流转,也就会面临一些困境,这些困境,是由于数据在不同世界中的表现形式不同而造成的.   数据在页面上是一个扁平的,不带数据类 ...

  2. Spring MVC 中采用注解方式 Action中跳转到另一个Action的写法

    Spring MVC 中采用注解方式 Action中跳转到另一个Action的写法 在Action中方法的返回值都是字符串行,一般情况是返回某个JSP,如: return "xx" ...

  3. mybatis实战教程(mybatis in action)之六:与Spring MVC 的集成

    前面几篇文章已经讲到了mybatis与spring 的集成.但这个时候,所有的工程还不是web工程,虽然我一直是创建的web 工程.今天将直接用mybatis与Spring mvc 的方式集成起来,源 ...

  4. Spring MVC 的 XML 配置方式

    索引: 开源Spring解决方案--lm.solution 参看代码 GitHub: solution/pom.xml solution/webapi/pom.xml solution/mapper/ ...

  5. Mybatis学习(6)与Spring MVC 的集成

    前面几篇文章已经讲到了mybatis与spring 的集成.但这个时候,所有的工程还不是web工程,虽然我一直是创建的web 工程.今天将直接用mybatis与Spring mvc 的方式集成起来,源 ...

  6. Spring MVC拦截器+注解方式实现防止表单重复提交

    原理:在新建页面中Session保存token随机码,当保存时验证,通过后删除,当再次点击保存时由于服务器端的Session中已经不存在了,所有无法验证通过. 注,如果是集群的方式,则需要将token ...

  7. spring mvc 异常统一处理方式

    springMVC提供的异常处理主要有两种方式: 一种是直接实现自己的HandlerExceptionResolver: 另一种是使用注解的方式实现一个专门用于处理异常的Controller——Exc ...

  8. Spring MVC Controller中GET方式传过来的中文参数会乱码的问题

    Spring MVC controller 这样写法通常意味着访问该请求,GET和POST请求都行,可是经常会遇到,如果碰到参数是中文的,post请求可以,get请求过来就是乱码.如果强行对参数进行了 ...

  9. html form method 属性不支持put,delete请求方式,以及开启spring mvc的rest的方式

    1.加上隐藏域解决form method 不支持put,delete的请求方式的问题 2.配置spring mvc HiddenHttpMethodFilter过滤器实现对put和delete请求方式 ...

  10. spring mvc 多库连接

    最近弄了个spring mvc + hibernate4为框架的项目,其中需用到其他两个库的数据.具体如下: 1.将两库的application文件配置好,需注意的地方是两个事务控制是不一样的. 和 ...

随机推荐

  1. Jobs深入学习

    代码回顾 Quartz 需要了解你可能希望该作业的实例拥有的各种属性,这是通过JobDetail 类完成的.  JobDetail 实例是使用 JobBuilder 类构建的. JobDetail j ...

  2. python 的序列化和反序列化

    什么是序列化?简单来说就是将数据存储到物理内存上的过程叫序列化. 什么是反序列化?将数据从物理内存存储到程序内存的过程叫做反序列化. 下面来看一下python中使用json进行序列化和反序列化的实例d ...

  3. 195. Spring Boot 2.0数据库迁移:Flyway

    [视频&交流平台] àSpringBoot视频:http://t.cn/R3QepWG à SpringCloud视频:http://t.cn/R3QeRZc à Spring Boot源码: ...

  4. 星级评分原理 N次重写的分析

    使用的是雪碧图,用的软件是CSS Sprite Tools 第一次实现与分析: <!DOCTYPE html> <html> <head> <meta cha ...

  5. python常用库,包网址

    常用包下载:https://pypi.org/ 1.NumPy: https://www.numpy.org/ 2.pandas: http://pandas.pydata.org/ 3.SciPy: ...

  6. oracle 创建表,删除表,修改表,查询表

    1,获取当前用户下的所有表信息 =>  SELECT * FROM user_tables 1.1,查询某一张表的字段信息:SELECT  *  FROM user_tab_columns  w ...

  7. leetcode208

    class TrieNode { public: // Initialize your data structure here. TrieNode() { words=; prefixs=; ;i&l ...

  8. subString(index,end) 用法

    sb = sb.Substring(0, sb.Length - 1); 获取当前字符串的前一部分去掉最后一个字符

  9. 尚硅谷springboot学习32-整合druid

    使用druid数据源 配置druid数据源 这里配置的数据源参数并不会生效,因为在DataSourceProperties中并没有这些字段,如果想要生效,必须自己配置druid数据源 @Configu ...

  10. Mybatis Generator 生成的mapper只有insert方法

    一般有两种情况 第一种是配置问题可以参考博客 http://blog.csdn.net/angel_xiaa/article/details/52474022 第二种是mysql-connector- ...