Intellij-IDEA-maven+springMVC+mybatis整合DEMO
1.实现了多数据源配置。 2.实现动态切换数据源核心配置。 过程:1).配置applicationContext-dao-multiple.xml文件 2).查看MultipleDataSourceAspectAdvice.java MultipleDataSource.java 两个文件
3.访问 http://localhost:8080/itemList1.action 访问了DataSource1 http://localhost:8080/itemList.action 访问了DataSource2
4.数据库创建语句
====================================== /* Navicat MySQL Data Transfer
Source Server : localhost_3306 Source Server Version : 50611 Source Host : localhost:3306 Source Database : springmvc
Target Server Type : MYSQL Target Server Version : 50611 File Encoding : 65001
Date: 2016-05-09 19:45:13 */
SET FOREIGN_KEY_CHECKS=0;
-- Table structure for items
DROP TABLE IF EXISTS items;
CREATE TABLE items (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(32) NOT NULL COMMENT '商品名称',
price float(10,1) NOT NULL COMMENT '商品定价',
detail text COMMENT '商品描述',
pic varchar(64) DEFAULT NULL COMMENT '商品图片',
createtime datetime NOT NULL COMMENT '生产日期',
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
-- Records of items
INSERT INTO items VALUES ('1', '台式机', '3000.0', '该电脑质量非常好!!!!', null, '2016-02-03 13:22:53');
INSERT INTO items VALUES ('2', '笔记本', '6000.0', '笔记本性能好,质量好!!!!!', null, '2015-02-09 13:22:57');
INSERT INTO items VALUES ('3', '背包', '200.0', '名牌背包,容量大质量好!!!!', null, '2015-02-06 13:23:02');
-- Table structure for user
DROP TABLE IF EXISTS user;
CREATE TABLE user (
id int(11) NOT NULL AUTO_INCREMENT,
username varchar(32) NOT NULL COMMENT '用户名称',
birthday date DEFAULT NULL COMMENT '生日',
sex char(1) DEFAULT NULL COMMENT '性别',
address varchar(256) DEFAULT NULL COMMENT '地址',
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8;
-- Records of user
INSERT INTO user VALUES ('1', '王五', null, '2', null);
INSERT INTO user VALUES ('10', '张三', '2014-07-10', '1', '北京市');
INSERT INTO user VALUES ('16', '张小明', null, '1', '河南郑州');
INSERT INTO user VALUES ('22', '陈小明', null, '1', '河南郑州');
INSERT INTO user VALUES ('24', '张三丰', null, '1', '河南郑州');
INSERT INTO user VALUES ('25', '陈小明', null, '1', '河南郑州');
INSERT INTO user VALUES ('26', '王五', null, null, null);
=======================================================================