Browse Source

spring-boot-mybatis-mulidatasource

ityouknow 8 years ago
parent
commit
effaf3f8c6
17 changed files with 635 additions and 0 deletions
  1. 69 0
      spring-boot-mybatis-mulidatasource/pom.xml
  2. 13 0
      spring-boot-mybatis-mulidatasource/src/main/java/com/neo/Application.java
  3. 53 0
      spring-boot-mybatis-mulidatasource/src/main/java/com/neo/datasource/DataSource1Config.java
  4. 48 0
      spring-boot-mybatis-mulidatasource/src/main/java/com/neo/datasource/DataSource2Config.java
  5. 73 0
      spring-boot-mybatis-mulidatasource/src/main/java/com/neo/entity/UserEntity.java
  6. 5 0
      spring-boot-mybatis-mulidatasource/src/main/java/com/neo/enums/UserSexEnum.java
  7. 19 0
      spring-boot-mybatis-mulidatasource/src/main/java/com/neo/mapper/test1/User1Mapper.java
  8. 19 0
      spring-boot-mybatis-mulidatasource/src/main/java/com/neo/mapper/test2/User2Mapper.java
  9. 51 0
      spring-boot-mybatis-mulidatasource/src/main/java/com/neo/web/UserController.java
  10. 13 0
      spring-boot-mybatis-mulidatasource/src/main/resources/application.properties
  11. 55 0
      spring-boot-mybatis-mulidatasource/src/main/resources/mybatis/mapper/test1/UserMapper.xml
  12. 55 0
      spring-boot-mybatis-mulidatasource/src/main/resources/mybatis/mapper/test2/UserMapper.xml
  13. 12 0
      spring-boot-mybatis-mulidatasource/src/main/resources/mybatis/mybatis-config.xml
  14. 17 0
      spring-boot-mybatis-mulidatasource/src/test/java/com/neo/ApplicationTests.java
  15. 52 0
      spring-boot-mybatis-mulidatasource/src/test/java/com/neo/mapper/User1MapperTest.java
  16. 51 0
      spring-boot-mybatis-mulidatasource/src/test/java/com/neo/mapper/User2MapperTest.java
  17. 30 0
      spring-boot-mybatis-mulidatasource/users.sql

+ 69 - 0
spring-boot-mybatis-mulidatasource/pom.xml

@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+
+	<groupId>com.neo</groupId>
+	<artifactId>spring-boot-mybatis-mulidatasource</artifactId>
+	<version>1.0.0</version>
+	<packaging>jar</packaging>
+
+	<name>spring-boot-mybatis-mulidatasource</name>
+	<description>Demo project for Spring Boot and mybatis</description>
+
+	<parent>
+		<groupId>org.springframework.boot</groupId>
+		<artifactId>spring-boot-starter-parent</artifactId>
+		<version>1.4.2.RELEASE</version>
+		<relativePath/> <!-- lookup parent from repository -->
+	</parent>
+
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+		<java.version>1.8</java.version>
+	</properties>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-test</artifactId>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+	        <groupId>org.springframework.boot</groupId>
+	        <artifactId>spring-boot-starter-web</artifactId>
+	    </dependency>
+		<dependency>
+			<groupId>org.mybatis.spring.boot</groupId>
+			<artifactId>mybatis-spring-boot-starter</artifactId>
+			<version>1.1.1</version>
+		</dependency>
+	     <dependency>
+	        <groupId>mysql</groupId>
+	        <artifactId>mysql-connector-java</artifactId>
+	    </dependency>
+	     <dependency>
+	        <groupId>org.springframework.boot</groupId>
+	        <artifactId>spring-boot-devtools</artifactId>
+	        <optional>true</optional>
+		</dependency>
+	</dependencies>
+	
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.springframework.boot</groupId>
+				<artifactId>spring-boot-maven-plugin</artifactId>
+				<configuration>
+	                <fork>true</fork>
+	            </configuration>
+			</plugin>
+		</plugins>
+	</build>
+	
+
+</project>

+ 13 - 0
spring-boot-mybatis-mulidatasource/src/main/java/com/neo/Application.java

@@ -0,0 +1,13 @@
+package com.neo;
+
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class Application {
+
+	public static void main(String[] args) {
+		SpringApplication.run(Application.class, args);
+	}
+}

+ 53 - 0
spring-boot-mybatis-mulidatasource/src/main/java/com/neo/datasource/DataSource1Config.java

@@ -0,0 +1,53 @@
+package com.neo.datasource;
+
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.mybatis.spring.SqlSessionFactoryBean;
+import org.mybatis.spring.SqlSessionTemplate;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+
+import javax.sql.DataSource;
+
+/**
+ * Created by summer on 2016/11/25.
+ */
+@Configuration
+@MapperScan(basePackages = "com.neo.mapper.test1", sqlSessionTemplateRef  = "test1SqlSessionTemplate")
+public class DataSource1Config {
+
+    @Bean(name = "test1DataSource")
+    @ConfigurationProperties(prefix = "spring.datasource.test1")
+    @Primary
+    public DataSource testDataSource() {
+        return DataSourceBuilder.create().build();
+    }
+
+    @Bean(name = "test1SqlSessionFactory")
+    @Primary
+    public SqlSessionFactory testSqlSessionFactory(@Qualifier("test1DataSource") DataSource dataSource) throws Exception {
+        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
+        bean.setDataSource(dataSource);
+        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mapper/test1/*.xml"));
+        return bean.getObject();
+    }
+
+    @Bean(name = "test1TransactionManager")
+    @Primary
+    public DataSourceTransactionManager testTransactionManager(@Qualifier("test1DataSource") DataSource dataSource) {
+        return new DataSourceTransactionManager(dataSource);
+    }
+
+    @Bean(name = "test1SqlSessionTemplate")
+    @Primary
+    public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("test1SqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
+        return new SqlSessionTemplate(sqlSessionFactory);
+    }
+
+}

+ 48 - 0
spring-boot-mybatis-mulidatasource/src/main/java/com/neo/datasource/DataSource2Config.java

@@ -0,0 +1,48 @@
+package com.neo.datasource;
+
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.mybatis.spring.SqlSessionFactoryBean;
+import org.mybatis.spring.SqlSessionTemplate;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+
+import javax.sql.DataSource;
+
+/**
+ * Created by summer on 2016/11/25.
+ */
+@Configuration
+@MapperScan(basePackages = "com.neo.mapper.test2", sqlSessionTemplateRef  = "test2SqlSessionTemplate")
+public class DataSource2Config {
+
+    @Bean(name = "test2DataSource")
+    @ConfigurationProperties(prefix = "spring.datasource.test2")
+    public DataSource testDataSource() {
+        return DataSourceBuilder.create().build();
+    }
+
+    @Bean(name = "test2SqlSessionFactory")
+    public SqlSessionFactory testSqlSessionFactory(@Qualifier("test2DataSource") DataSource dataSource) throws Exception {
+        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
+        bean.setDataSource(dataSource);
+        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mapper/test2/*.xml"));
+        return bean.getObject();
+    }
+
+    @Bean(name = "test2TransactionManager")
+    public DataSourceTransactionManager testTransactionManager(@Qualifier("test2DataSource") DataSource dataSource) {
+        return new DataSourceTransactionManager(dataSource);
+    }
+
+    @Bean(name = "test2SqlSessionTemplate")
+    public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("test2SqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
+        return new SqlSessionTemplate(sqlSessionFactory);
+    }
+
+}

+ 73 - 0
spring-boot-mybatis-mulidatasource/src/main/java/com/neo/entity/UserEntity.java

@@ -0,0 +1,73 @@
+package com.neo.entity;
+
+import java.io.Serializable;
+
+import com.neo.enums.UserSexEnum;
+
+public class UserEntity implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+	private Long id;
+	private String userName;
+	private String passWord;
+	private UserSexEnum userSex;
+	private String nickName;
+
+	public UserEntity() {
+		super();
+	}
+
+	public UserEntity(String userName, String passWord, UserSexEnum userSex) {
+		super();
+		this.passWord = passWord;
+		this.userName = userName;
+		this.userSex = userSex;
+	}
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public String getUserName() {
+		return userName;
+	}
+
+	public void setUserName(String userName) {
+		this.userName = userName;
+	}
+
+	public String getPassWord() {
+		return passWord;
+	}
+
+	public void setPassWord(String passWord) {
+		this.passWord = passWord;
+	}
+
+	public UserSexEnum getUserSex() {
+		return userSex;
+	}
+
+	public void setUserSex(UserSexEnum userSex) {
+		this.userSex = userSex;
+	}
+
+	public String getNickName() {
+		return nickName;
+	}
+
+	public void setNickName(String nickName) {
+		this.nickName = nickName;
+	}
+
+	@Override
+	public String toString() {
+		// TODO Auto-generated method stub
+		return "userName " + this.userName + ", pasword " + this.passWord + "sex " + userSex.name();
+	}
+
+}

+ 5 - 0
spring-boot-mybatis-mulidatasource/src/main/java/com/neo/enums/UserSexEnum.java

@@ -0,0 +1,5 @@
+package com.neo.enums;
+
+public enum UserSexEnum {
+	MAN, WOMAN
+}

+ 19 - 0
spring-boot-mybatis-mulidatasource/src/main/java/com/neo/mapper/test1/User1Mapper.java

@@ -0,0 +1,19 @@
+package com.neo.mapper.test1;
+
+import com.neo.entity.UserEntity;
+
+import java.util.List;
+
+public interface User1Mapper {
+	
+	List<UserEntity> getAll();
+	
+	UserEntity getOne(Long id);
+
+	void insert(UserEntity user);
+
+	void update(UserEntity user);
+
+	void delete(Long id);
+
+}

+ 19 - 0
spring-boot-mybatis-mulidatasource/src/main/java/com/neo/mapper/test2/User2Mapper.java

@@ -0,0 +1,19 @@
+package com.neo.mapper.test2;
+
+import java.util.List;
+
+import com.neo.entity.UserEntity;
+
+public interface User2Mapper {
+	
+	List<UserEntity> getAll();
+	
+	UserEntity getOne(Long id);
+
+	void insert(UserEntity user);
+
+	void update(UserEntity user);
+
+	void delete(Long id);
+
+}

+ 51 - 0
spring-boot-mybatis-mulidatasource/src/main/java/com/neo/web/UserController.java

@@ -0,0 +1,51 @@
+package com.neo.web;
+
+import java.util.List;
+
+import com.neo.mapper.test1.User1Mapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.neo.entity.UserEntity;
+import com.neo.mapper.test2.User2Mapper;
+
+@RestController
+public class UserController {
+
+    @Autowired
+    private User1Mapper user1Mapper;
+
+	@Autowired
+	private User2Mapper user2Mapper;
+	
+	@RequestMapping("/getUsers")
+	public List<UserEntity> getUsers() {
+		List<UserEntity> users=user1Mapper.getAll();
+		return users;
+	}
+	
+    @RequestMapping("/getUser")
+    public UserEntity getUser(Long id) {
+    	UserEntity user=user2Mapper.getOne(id);
+        return user;
+    }
+    
+    @RequestMapping("/add")
+    public void save(UserEntity user) {
+        user2Mapper.insert(user);
+    }
+    
+    @RequestMapping(value="update")
+    public void update(UserEntity user) {
+        user2Mapper.update(user);
+    }
+    
+    @RequestMapping(value="/delete/{id}")
+    public void delete(@PathVariable("id") Long id) {
+        user1Mapper.delete(id);
+    }
+    
+    
+}

+ 13 - 0
spring-boot-mybatis-mulidatasource/src/main/resources/application.properties

@@ -0,0 +1,13 @@
+mybatis.config-locations=classpath:mybatis/mybatis-config.xml
+
+spring.datasource.test1.driverClassName = com.mysql.jdbc.Driver
+spring.datasource.test1.url = jdbc:mysql://localhost:3306/test1?useUnicode=true&characterEncoding=utf-8
+spring.datasource.test1.username = root
+spring.datasource.test1.password = root
+
+
+spring.datasource.test2.driverClassName = com.mysql.jdbc.Driver
+spring.datasource.test2.url = jdbc:mysql://localhost:3306/test2?useUnicode=true&characterEncoding=utf-8
+spring.datasource.test2.username = root
+spring.datasource.test2.password = root
+

+ 55 - 0
spring-boot-mybatis-mulidatasource/src/main/resources/mybatis/mapper/test1/UserMapper.xml

@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.neo.mapper.test1.User1Mapper" >
+    <resultMap id="BaseResultMap" type="com.neo.entity.UserEntity" >
+        <id column="id" property="id" jdbcType="BIGINT" />
+        <result column="userName" property="userName" jdbcType="VARCHAR" />
+        <result column="passWord" property="passWord" jdbcType="VARCHAR" />
+        <result column="user_sex" property="userSex" javaType="com.neo.enums.UserSexEnum"/>
+        <result column="nick_name" property="nickName" jdbcType="VARCHAR" />
+    </resultMap>
+    
+    <sql id="Base_Column_List" >
+        id, userName, passWord, user_sex, nick_name
+    </sql>
+
+    <select id="getAll" resultMap="BaseResultMap"  >
+       SELECT 
+       <include refid="Base_Column_List" />
+	   FROM users
+    </select>
+
+    <select id="getOne" parameterType="java.lang.Long" resultMap="BaseResultMap" >
+        SELECT 
+       <include refid="Base_Column_List" />
+	   FROM users
+	   WHERE id = #{id}
+    </select>
+
+    <insert id="insert" parameterType="com.neo.entity.UserEntity" >
+       INSERT INTO 
+       		users
+       		(userName,passWord,user_sex) 
+       	VALUES
+       		(#{userName}, #{passWord}, #{userSex})
+    </insert>
+    
+    <update id="update" parameterType="com.neo.entity.UserEntity" >
+       UPDATE 
+       		users 
+       SET 
+       	<if test="userName != null">userName = #{userName},</if>
+       	<if test="passWord != null">passWord = #{passWord},</if>
+       	nick_name = #{nickName}
+       WHERE 
+       		id = #{id}
+    </update>
+    
+    <delete id="delete" parameterType="java.lang.Long" >
+       DELETE FROM
+       		 users 
+       WHERE 
+       		 id =#{id}
+    </delete>
+
+</mapper>

+ 55 - 0
spring-boot-mybatis-mulidatasource/src/main/resources/mybatis/mapper/test2/UserMapper.xml

@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.neo.mapper.test2.User2Mapper" >
+    <resultMap id="BaseResultMap" type="com.neo.entity.UserEntity" >
+        <id column="id" property="id" jdbcType="BIGINT" />
+        <result column="userName" property="userName" jdbcType="VARCHAR" />
+        <result column="passWord" property="passWord" jdbcType="VARCHAR" />
+        <result column="user_sex" property="userSex" javaType="com.neo.enums.UserSexEnum"/>
+        <result column="nick_name" property="nickName" jdbcType="VARCHAR" />
+    </resultMap>
+    
+    <sql id="Base_Column_List" >
+        id, userName, passWord, user_sex, nick_name
+    </sql>
+
+    <select id="getAll" resultMap="BaseResultMap"  >
+       SELECT 
+       <include refid="Base_Column_List" />
+	   FROM users
+    </select>
+
+    <select id="getOne" parameterType="java.lang.Long" resultMap="BaseResultMap" >
+        SELECT 
+       <include refid="Base_Column_List" />
+	   FROM users
+	   WHERE id = #{id}
+    </select>
+
+    <insert id="insert" parameterType="com.neo.entity.UserEntity" >
+       INSERT INTO 
+       		users
+       		(userName,passWord,user_sex) 
+       	VALUES
+       		(#{userName}, #{passWord}, #{userSex})
+    </insert>
+    
+    <update id="update" parameterType="com.neo.entity.UserEntity" >
+       UPDATE 
+       		users 
+       SET 
+       	<if test="userName != null">userName = #{userName},</if>
+       	<if test="passWord != null">passWord = #{passWord},</if>
+       	nick_name = #{nickName}
+       WHERE 
+       		id = #{id}
+    </update>
+    
+    <delete id="delete" parameterType="java.lang.Long" >
+       DELETE FROM
+       		 users 
+       WHERE 
+       		 id =#{id}
+    </delete>
+
+</mapper>

+ 12 - 0
spring-boot-mybatis-mulidatasource/src/main/resources/mybatis/mybatis-config.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
+<configuration>
+	<typeAliases>
+		<typeAlias alias="Integer" type="java.lang.Integer" />
+		<typeAlias alias="Long" type="java.lang.Long" />
+		<typeAlias alias="HashMap" type="java.util.HashMap" />
+		<typeAlias alias="LinkedHashMap" type="java.util.LinkedHashMap" />
+		<typeAlias alias="ArrayList" type="java.util.ArrayList" />
+		<typeAlias alias="LinkedList" type="java.util.LinkedList" />
+	</typeAliases>
+</configuration>

+ 17 - 0
spring-boot-mybatis-mulidatasource/src/test/java/com/neo/ApplicationTests.java

@@ -0,0 +1,17 @@
+package com.neo;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class ApplicationTests {
+
+	@Test
+	public void contextLoads() {
+		System.out.println("hello world");
+	}
+
+}

+ 52 - 0
spring-boot-mybatis-mulidatasource/src/test/java/com/neo/mapper/User1MapperTest.java

@@ -0,0 +1,52 @@
+package com.neo.mapper;
+
+import java.util.List;
+
+import com.neo.mapper.test1.User1Mapper;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import com.neo.entity.UserEntity;
+import com.neo.enums.UserSexEnum;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class User1MapperTest {
+
+	@Autowired
+	private User1Mapper userMapper;
+
+	@Test
+	public void testInsert() throws Exception {
+		userMapper.insert(new UserEntity("aa", "a123456", UserSexEnum.MAN));
+		userMapper.insert(new UserEntity("bb", "b123456", UserSexEnum.WOMAN));
+		userMapper.insert(new UserEntity("cc", "b123456", UserSexEnum.WOMAN));
+
+		Assert.assertEquals(3, userMapper.getAll().size());
+	}
+
+	@Test
+	public void testQuery() throws Exception {
+		List<UserEntity> users = userMapper.getAll();
+		if(users==null || users.size()==0){
+			System.out.println("is null");
+		}else{
+			System.out.println(users.size());
+		}
+	}
+	
+	
+	@Test
+	public void testUpdate() throws Exception {
+		UserEntity user = userMapper.getOne(6l);
+		System.out.println(user.toString());
+		user.setNickName("neo");
+		userMapper.update(user);
+		Assert.assertTrue(("neo".equals(userMapper.getOne(6l).getNickName())));
+	}
+
+}

+ 51 - 0
spring-boot-mybatis-mulidatasource/src/test/java/com/neo/mapper/User2MapperTest.java

@@ -0,0 +1,51 @@
+package com.neo.mapper;
+
+import com.neo.entity.UserEntity;
+import com.neo.enums.UserSexEnum;
+import com.neo.mapper.test2.User2Mapper;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.List;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class User2MapperTest {
+
+	@Autowired
+	private User2Mapper userMapper;
+
+	@Test
+	public void testInsert() throws Exception {
+		userMapper.insert(new UserEntity("aa", "a123456", UserSexEnum.MAN));
+		userMapper.insert(new UserEntity("bb", "b123456", UserSexEnum.WOMAN));
+		userMapper.insert(new UserEntity("cc", "b123456", UserSexEnum.WOMAN));
+
+		Assert.assertEquals(3, userMapper.getAll().size());
+	}
+
+	@Test
+	public void testQuery() throws Exception {
+		List<UserEntity> users = userMapper.getAll();
+		if(users==null || users.size()==0){
+			System.out.println("is null");
+		}else{
+			System.out.println(users.toString());
+		}
+	}
+	
+	
+	@Test
+	public void testUpdate() throws Exception {
+		UserEntity user = userMapper.getOne(6l);
+		System.out.println(user.toString());
+		user.setNickName("neo");
+		userMapper.update(user);
+		Assert.assertTrue(("neo".equals(userMapper.getOne(6l).getNickName())));
+	}
+
+}

+ 30 - 0
spring-boot-mybatis-mulidatasource/users.sql

@@ -0,0 +1,30 @@
+/*
+Navicat MySQL Data Transfer
+
+Source Server         : 本地
+Source Server Version : 50505
+Source Host           : localhost:3306
+Source Database       : test1
+
+Target Server Type    : MYSQL
+Target Server Version : 50505
+File Encoding         : 65001
+
+Date: 2016-11-05 21:17:33
+*/
+
+SET FOREIGN_KEY_CHECKS=0;
+
+-- ----------------------------
+-- Table structure for `users`
+-- ----------------------------
+DROP TABLE IF EXISTS `users`;
+CREATE TABLE `users` (
+  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键id',
+  `userName` varchar(32) DEFAULT NULL COMMENT '用户名',
+  `passWord` varchar(32) DEFAULT NULL COMMENT '密码',
+  `user_sex` varchar(32) DEFAULT NULL,
+  `nick_name` varchar(32) DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8;
+