[
  {
    "path": ".gitignore",
    "content": "*.class\n\n# Mobile Tools for Java (J2ME)\n.mtj.tmp/\n\n# Package Files #\n*.jar\n*.war\n*.ear\n.idea/\ntarget/\n*.iml\n\n# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml\nhs_err_pid*\n"
  },
  {
    "path": "LICENSE",
    "content": "                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"{}\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright {yyyy} {name of copyright owner}\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "README.md",
    "content": "# springboot-multiple-dataSources\n\n### 前言 ###\n\nspring-boot多数据源自动切换例子项目， 利用spring aop 切面，自动切换数据源。\n\nCommonServiceImpl是公共处理类，Test1ServiceImpl和Test2ServiceImpl是两个数据源分别的业务处理类。定义DataSourceAspect类处理切面。\n\nspringboot-multiple-dataSources/src/main/resources目录下的database1.sql和database2.sql是2个数据源初始化脚本\n\n### 软件环境 ###\nIntelliJ IDEA 2016.3.3(或eclipse)\n\njdk 1.8\n\nmaven 3.3.9\n\n### 使用的技术 ###\n\n- spring-boot\n- springmvc\n- mybatis\n- 通用mapper(一个非常好用的mybatis插件, 详细介绍见http://git.oschina.net/free/Mapper)\n\n### 在IDE 中查看源码并运行 ###\n\n**1. 在IntelliJ IDEA (推荐使用)**\n\nFile -> Import Project -> select springboot-multiple-dataSources folder -> create project form existing sources -> ...\n\n**2. 在Eclipse**\n\nFile -> Import -> Existing Maven Projects -> ...\n"
  },
  {
    "path": "pom.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n         xmlns=\"http://maven.apache.org/POM/4.0.0\"\n         xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n    <modelVersion>4.0.0</modelVersion>\n\n    <groupId>com.huan</groupId>\n    <artifactId>springboot-multiple-dataSources</artifactId>\n    <version>1.0-SNAPSHOT</version>\n    <packaging>war</packaging>\n\n    <properties>\n        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\n        <!--  MyBatis Generator  -->\n        <!--  Java接口和实体类  -->\n        <targetJavaProject>${basedir}/src/main/java</targetJavaProject>\n        <targetMapperPackage>com.huan.mapper</targetMapperPackage>\n        <targetModelPackage>com.huan.model</targetModelPackage>\n        <!--  XML生成路径  -->\n        <targetResourcesProject>${basedir}/src/main/resources</targetResourcesProject>\n        <targetXMLPackage>mapper</targetXMLPackage>\n        <mysql.version>5.1.42</mysql.version>\n        <junit.version>4.12</junit.version>\n        <mapper.version>3.4.0</mapper.version>\n        <pagehelper.version>4.1.6</pagehelper.version>\n        <logback.version>1.1.7</logback.version>\n    </properties>\n\n    <parent>\n        <groupId>org.springframework.boot</groupId>\n        <artifactId>spring-boot-starter-parent</artifactId>\n        <version>1.5.2.RELEASE</version>\n    </parent>\n\n    <dependencies>\n        <dependency>\n            <groupId>junit</groupId>\n            <artifactId>junit</artifactId>\n            <version>${junit.version}</version>\n            <scope>test</scope>\n        </dependency>\n        <dependency>\n            <groupId>org.slf4j</groupId>\n            <artifactId>slf4j-api</artifactId>\n            <version>1.7.21</version>\n        </dependency>\n        <!-- LogBack dependencies -->\n        <dependency>\n            <groupId>ch.qos.logback</groupId>\n            <artifactId>logback-classic</artifactId>\n            <version>${logback.version}</version>\n        </dependency>\n        <dependency>\n            <groupId>ch.qos.logback</groupId>\n            <artifactId>logback-core</artifactId>\n            <version>${logback.version}</version>\n        </dependency>\n        <dependency>\n            <groupId>javax.servlet</groupId>\n            <artifactId>javax.servlet-api</artifactId>\n            <version>3.1.0</version>\n            <scope>provided</scope>\n        </dependency>\n\n        <!-- springboot-->\n        <dependency>\n            <groupId>org.springframework.boot</groupId>\n            <artifactId>spring-boot-starter-web</artifactId>\n        </dependency>\n        <dependency>\n            <groupId>org.springframework.boot</groupId>\n            <artifactId>spring-boot-starter-data-jpa</artifactId>\n        </dependency>\n        <dependency>\n            <groupId>org.springframework.boot</groupId>\n            <artifactId>spring-boot-starter-freemarker</artifactId>\n        </dependency>\n        <!--mysql-->\n        <dependency>\n            <groupId>mysql</groupId>\n            <artifactId>mysql-connector-java</artifactId>\n            <version>${mysql.version}</version>\n        </dependency>\n        <!--druid-->\n        <dependency>\n            <groupId>com.alibaba</groupId>\n            <artifactId>druid</artifactId>\n            <version>1.0.31</version>\n        </dependency>\n\n        <!--Mybatis-->\n        <dependency>\n            <groupId>org.mybatis</groupId>\n            <artifactId>mybatis</artifactId>\n            <version>3.4.4</version>\n        </dependency>\n        <dependency>\n            <groupId>org.mybatis</groupId>\n            <artifactId>mybatis-spring</artifactId>\n            <version>1.3.1</version>\n        </dependency>\n        <!-- Mybatis Generator -->\n        <dependency>\n            <groupId>org.mybatis.generator</groupId>\n            <artifactId>mybatis-generator-core</artifactId>\n            <version>1.3.5</version>\n            <scope>compile</scope>\n            <optional>true</optional>\n        </dependency>\n        <!--通用Mapper-->\n        <dependency>\n            <groupId>tk.mybatis</groupId>\n            <artifactId>mapper</artifactId>\n            <version>${mapper.version}</version>\n        </dependency>\n\n    </dependencies>\n\n    <build>\n        <resources>\n            <resource>\n                <directory>${basedir}/src/main/java</directory>\n                <includes>\n                    <include>**/*.xml</include>\n                </includes>\n            </resource>\n            <resource>\n                <directory>${basedir}/src/main/resources</directory>\n            </resource>\n        </resources>\n        <plugins>\n            <plugin>\n                <groupId>org.mybatis.generator</groupId>\n                <artifactId>mybatis-generator-maven-plugin</artifactId>\n                <version>1.3.5</version>\n                <configuration>\n                    <configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>\n                    <overwrite>true</overwrite>\n                    <verbose>true</verbose>\n                </configuration>\n                <dependencies>\n                    <dependency>\n                        <groupId>mysql</groupId>\n                        <artifactId>mysql-connector-java</artifactId>\n                        <version>${mysql.version}</version>\n                    </dependency>\n                    <dependency>\n                        <groupId>tk.mybatis</groupId>\n                        <artifactId>mapper</artifactId>\n                        <version>${mapper.version}</version>\n                    </dependency>\n                </dependencies>\n            </plugin>\n            <plugin>\n                <groupId>org.springframework.boot</groupId>\n                <artifactId>spring-boot-maven-plugin</artifactId>\n                <configuration>\n                    <executable>true</executable>\n                </configuration>\n            </plugin>\n            <plugin>\n                <groupId>org.apache.maven.plugins</groupId>\n                <artifactId>maven-compiler-plugin</artifactId>\n                <version>3.5.1</version>\n                <configuration>\n                    <source>1.8</source>\n                    <target>1.8</target>\n                    <encoding>UTF-8</encoding>\n                </configuration>\n            </plugin>\n        </plugins>\n    </build>\n\n</project>"
  },
  {
    "path": "src/main/java/com/huan/Application.java",
    "content": "package com.huan;\n\nimport com.huan.config.AbstractApplication;\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\nimport org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;\n\nimport java.net.UnknownHostException;\n\n@SpringBootApplication(scanBasePackages = \"com.huan\", exclude = {DataSourceAutoConfiguration.class})\npublic class Application extends AbstractApplication {\n\n    public static void main(String[] args) throws UnknownHostException {\n        SpringApplication app = new SpringApplication(Application.class);\n        app.run(args);\n//        abstractMain(app, args);\n    }\n}\n"
  },
  {
    "path": "src/main/java/com/huan/config/AbstractApplication.java",
    "content": "package com.huan.config;\n\nimport com.huan.util.Constants;\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.builder.SpringApplicationBuilder;\nimport org.springframework.boot.web.support.SpringBootServletInitializer;\nimport org.springframework.core.env.ConfigurableEnvironment;\nimport org.springframework.core.env.Environment;\nimport org.springframework.core.env.SimpleCommandLinePropertySource;\n\nimport javax.annotation.PostConstruct;\nimport java.io.IOException;\nimport java.net.InetAddress;\nimport java.net.UnknownHostException;\nimport java.util.Arrays;\nimport java.util.Collection;\n\n/**\n * @author <a href=\"mailto:jean@eastcode.org\">Jean Seurin</a>\n * @since 12/11/15 - 10:16\n */\npublic class AbstractApplication extends SpringBootServletInitializer {\n\n    protected static final Logger logger = LoggerFactory.getLogger(AbstractApplication.class);\n    protected static Environment staticEnv;\n    @Autowired\n    protected ConfigurableEnvironment env;\n\n    protected static void abstractMain(SpringApplication app, String[] args) throws UnknownHostException {\n        SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);\n        addDefaultProfile(app, source);\n        //addLiquibaseScanPackages();\n        staticEnv = app.run(args).getEnvironment();\n        showAppInfo(staticEnv);\n    }\n\n    protected static void showAppInfo(final Environment env) throws UnknownHostException {\n        String isSslEnabled = env.getProperty(\"server.ssl.enabled\");\n        String protocol = \"http\";\n        if (isSslEnabled != null && \"true\".equals(isSslEnabled)) {\n            protocol = \"https\";\n        }\n        logger.info(\"Access URLs:\\n----------------------------------------------------------\\n\\t\" +\n                        \"Local: \\t\\t\" + protocol + \"://127.0.0.1:{}\\n\\t\" +\n                        \"External: \\t\" + protocol + \"://{}:{}\\n----------------------------------------------------------\",\n                env.getProperty(\"server.port\"),\n                InetAddress.getLocalHost().getHostAddress(),\n                env.getProperty(\"server.port\"));\n    }\n\n    /**\n     * If no profile has been configured, set by default the \"dev\" profile.\n     */\n    protected static void addDefaultProfile(SpringApplication app, SimpleCommandLinePropertySource source) {\n        if ((System.getProperty(\"spring.profiles.active\") == null)\n                && !source.containsProperty(\"spring.profiles.active\")\n                && !System.getenv().containsKey(\"SPRING_PROFILES_ACTIVE\")) {\n            app.setAdditionalProfiles(Constants.SPRING_PROFILE_DEVELOPMENT);\n        }\n    }\n\n    @Override\n    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {\n        return application.sources(this.getClass());\n    }\n\n    /**\n     * Initializes the application. Do some checks on profile configuration\n     * <p>\n     * Spring profiles can be configured with a program arguments --spring.profiles.active=your-active-profile\n     * <p>\n     */\n    @PostConstruct\n    public void initApplication() throws IOException {\n        if (env.getActiveProfiles().length == 0) {\n            logger.warn(\"No Spring profile configured, running with default configuration\");\n        } else {\n            logger.info(\"Running with Spring profile(s) : {}\", Arrays.toString(env.getActiveProfiles()));\n            Collection activeProfiles = Arrays.asList(env.getActiveProfiles());\n            if (activeProfiles.contains(\"dev\") && activeProfiles.contains(\"prod\")) {\n                logger.error(\"You have misconfigured your application! It should not run with both the 'dev' and 'prod' profiles at the same time.\");\n            }\n            if (activeProfiles.contains(\"prod\") && activeProfiles.contains(\"fast\")) {\n                logger.error(\"You have misconfigured your application! It should not run with both the 'prod' and 'fast' profiles at the same time.\");\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "src/main/java/com/huan/config/DataSourceAspect.java",
    "content": "package com.huan.config;\n\nimport com.huan.service.Test1Service;\nimport com.huan.service.impl.Test1ServiceImpl;\nimport com.huan.util.DatabaseContextHolder;\nimport com.huan.util.DatabaseType;\nimport org.aspectj.lang.JoinPoint;\nimport org.aspectj.lang.annotation.Aspect;\nimport org.aspectj.lang.annotation.Before;\nimport org.aspectj.lang.annotation.Pointcut;\nimport org.springframework.stereotype.Component;\n\n@Aspect\n@Component\npublic class DataSourceAspect {\n\n    /**\n     * 使用空方法定义切点表达式\n     */\n    @Pointcut(\"execution(* com.huan.service.**.*(..))\")\n    public void declareJointPointExpression() {\n    }\n\n    @Before(\"declareJointPointExpression()\")\n    public void setDataSourceKey(JoinPoint point){\n        //根据连接点所属的类实例，动态切换数据源\n        if (point.getTarget() instanceof Test1Service\n                || point.getTarget() instanceof Test1ServiceImpl) {\n            DatabaseContextHolder.setDatabaseType(DatabaseType.test1);\n        } else {//连接点所属的类实例是（当然，这一步也可以不写，因为defaultTargertDataSource就是该类所用的mytestdb）\n            DatabaseContextHolder.setDatabaseType(DatabaseType.test2);\n        }\n    }\n}"
  },
  {
    "path": "src/main/java/com/huan/config/MyBatisConfig.java",
    "content": "package com.huan.config;\n\nimport com.alibaba.druid.pool.DruidDataSourceFactory;\nimport com.huan.util.DatabaseType;\nimport com.huan.util.DynamicDataSource;\nimport org.apache.ibatis.session.SqlSessionFactory;\nimport org.mybatis.spring.SqlSessionFactoryBean;\nimport org.springframework.beans.factory.annotation.Qualifier;\nimport org.springframework.context.EnvironmentAware;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\nimport org.springframework.context.annotation.Primary;\nimport org.springframework.core.env.Environment;\nimport org.springframework.core.io.support.PathMatchingResourcePatternResolver;\nimport org.springframework.jdbc.datasource.DataSourceTransactionManager;\nimport tk.mybatis.spring.mapper.MapperScannerConfigurer;\n\nimport javax.sql.DataSource;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Properties;\n\n/**\n * springboot集成mybatis的基本入口 1）创建数据源(如果采用的是默认的tomcat-jdbc数据源，则不需要)\n * 2）创建SqlSessionFactory 3）配置事务管理器，除非需要使用事务，否则不用配置\n */\n@Configuration // 该注解类似于spring配置文件\npublic class MyBatisConfig implements EnvironmentAware {\n\n    private Environment environment;\n\n    @Override\n    public void setEnvironment(final Environment environment) {\n        this.environment = environment;\n    }\n\n    /**\n     * 创建数据源(数据源的名称：方法名可以取为XXXDataSource(),XXX为数据库名称,该名称也就是数据源的名称)\n     */\n    @Bean\n    public DataSource test1DataSource() throws Exception {\n        Properties props = new Properties();\n        props.put(\"driverClassName\", environment.getProperty(\"test1-datasource.driverClassName\"));\n        props.put(\"url\", environment.getProperty(\"test1-datasource.url\"));\n        props.put(\"username\", environment.getProperty(\"test1-datasource.username\"));\n        props.put(\"password\", environment.getProperty(\"test1-datasource.password\"));\n        return DruidDataSourceFactory.createDataSource(props);\n    }\n\n    @Bean\n    public DataSource test2DataSource() throws Exception {\n        Properties props = new Properties();\n        props.put(\"driverClassName\", environment.getProperty(\"test2-datasource.driverClassName\"));\n        props.put(\"url\", environment.getProperty(\"test2-datasource.url\"));\n        props.put(\"username\", environment.getProperty(\"test2-datasource.username\"));\n        props.put(\"password\", environment.getProperty(\"test2-datasource.password\"));\n        return DruidDataSourceFactory.createDataSource(props);\n    }\n\n    /**\n     * @Primary 该注解表示在同一个接口有多个实现类可以注入的时候，默认选择哪一个，而不是让@autowire注解报错\n     * @Qualifier 根据名称进行注入，通常是在具有相同的多个类型的实例的一个注入（例如有多个DataSource类型的实例）\n     */\n    @Bean\n    @Primary\n    public DynamicDataSource dataSource(@Qualifier(\"test1DataSource\") DataSource test1DataSource,\n                                        @Qualifier(\"test2DataSource\") DataSource test2DataSource) {\n        Map<Object, Object> targetDataSources = new HashMap<>();\n        targetDataSources.put(DatabaseType.test1, test1DataSource);\n        targetDataSources.put(DatabaseType.test2, test2DataSource);\n\n        DynamicDataSource dataSource = new DynamicDataSource();\n        dataSource.setTargetDataSources(targetDataSources);// 该方法是AbstractRoutingDataSource的方法\n        dataSource.setDefaultTargetDataSource(test2DataSource);// 默认的datasource设置为myTestDbDataSource\n\n        return dataSource;\n    }\n\n    @Bean\n    public MapperScannerConfigurer mapperScannerConfigurer() {\n        MapperScannerConfigurer scannerConfigurer = new MapperScannerConfigurer();\n        scannerConfigurer.setBasePackage(\"com.huan.mapper\");\n        Properties props = new Properties();\n        props.setProperty(\"mappers\", \"tk.mybatis.mapper.common.Mapper\");\n        props.setProperty(\"IDENTITY\", \"MYSQL\");\n        props.setProperty(\"notEmpty\", \"true\");\n        scannerConfigurer.setProperties(props);\n        return scannerConfigurer;\n    }\n\n    /**\n     * 根据数据源创建SqlSessionFactory\n     */\n    @Bean\n    public SqlSessionFactory sqlSessionFactory(DynamicDataSource ds) throws Exception {\n        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();\n\n        SqlSessionFactoryBean fb = new SqlSessionFactoryBean();\n        fb.setDataSource(ds);// 指定数据源(这个必须有，否则报错)\n        // 下边两句仅仅用于*.xml文件，如果整个持久层操作不需要使用到xml文件的话（只用注解就可以搞定），则不加\n        fb.setTypeAliasesPackage(\"com.huan.model\");// 指定基包\n        fb.setMapperLocations(resolver.getResources(\"classpath:mapper/**/*.xml\"));//\n\n        return fb.getObject();\n    }\n\n\n\n    /**\n     * 配置事务管理器\n     */\n    @Bean\n    public DataSourceTransactionManager transactionManager(DynamicDataSource dataSource) throws Exception {\n        return new DataSourceTransactionManager(dataSource);\n    }\n\n\n}"
  },
  {
    "path": "src/main/java/com/huan/controller/TestDataSourceController.java",
    "content": "package com.huan.controller;\n\nimport com.huan.model.UserDetail;\nimport com.huan.model.UserInfo;\nimport com.huan.service.CommonService;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RequestMethod;\nimport org.springframework.web.bind.annotation.RestController;\n\nimport java.util.List;\n\n@RestController\npublic class TestDataSourceController {\n\n    @Autowired\n    private CommonService commonService;\n\n    @RequestMapping(value = \"/test1\", method = RequestMethod.GET)\n    public List<UserInfo> selectUser() {\n        System.out.println(\"查询第一个数据源\");\n        return commonService.selectUserInfo();\n    }\n\n    @RequestMapping(value = \"/test2\", method = RequestMethod.GET)\n    public List<UserDetail> userDetail() {\n        System.out.println(\"查询第二个数据源\");\n        return commonService.selectUserDetail();\n    }\n\n}"
  },
  {
    "path": "src/main/java/com/huan/controller/WelcomeController.java",
    "content": "package com.huan.controller;\n\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RestController;\n\nimport java.util.Date;\nimport java.util.HashMap;\nimport java.util.Map;\n\n/**\n * Created by huan on 2016/5/21.\n */\n@RestController\npublic class WelcomeController {\n\n    @RequestMapping(\"/\")\n    public Map welcome() {\n        Map model = new HashMap();\n        model.put(\"time\", new Date());\n        model.put(\"message\", \"Hello World\");\n        return model;\n    }\n\n}"
  },
  {
    "path": "src/main/java/com/huan/mapper/UserDetailMapper.java",
    "content": "package com.huan.mapper;\n\nimport com.huan.model.UserDetail;\nimport tk.mybatis.mapper.common.Mapper;\n\npublic interface UserDetailMapper extends Mapper<UserDetail> {\n}"
  },
  {
    "path": "src/main/java/com/huan/mapper/UserInfoMapper.java",
    "content": "package com.huan.mapper;\n\nimport com.huan.model.UserInfo;\n\nimport java.util.List;\n\npublic interface UserInfoMapper {\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method corresponds to the database table user_info\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    int deleteByPrimaryKey(String id);\n\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method corresponds to the database table user_info\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    int insert(UserInfo record);\n\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method corresponds to the database table user_info\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    UserInfo selectByPrimaryKey(String id);\n\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method corresponds to the database table user_info\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    List<UserInfo> selectAll();\n\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method corresponds to the database table user_info\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    int updateByPrimaryKey(UserInfo record);\n}"
  },
  {
    "path": "src/main/java/com/huan/model/UserDetail.java",
    "content": "package com.huan.model;\n\nimport javax.persistence.GeneratedValue;\nimport javax.persistence.GenerationType;\nimport javax.persistence.Id;\nimport javax.persistence.Table;\n\n@Table(name = \"user_detail\")\npublic class UserDetail {\n    @Id\n    @GeneratedValue(strategy = GenerationType.IDENTITY)\n    private Long id;\n\n    private String name;\n\n    private String qq;\n\n    /**\n     * @return id\n     */\n    public Long getId() {\n        return id;\n    }\n\n    /**\n     * @param id\n     */\n    public void setId(Long id) {\n        this.id = id;\n    }\n\n    /**\n     * @return name\n     */\n    public String getName() {\n        return name;\n    }\n\n    /**\n     * @param name\n     */\n    public void setName(String name) {\n        this.name = name;\n    }\n\n    /**\n     * @return qq\n     */\n    public String getQq() {\n        return qq;\n    }\n\n    /**\n     * @param qq\n     */\n    public void setQq(String qq) {\n        this.qq = qq;\n    }\n}"
  },
  {
    "path": "src/main/java/com/huan/model/UserInfo.java",
    "content": "package com.huan.model;\n\npublic class UserInfo {\n    /**\n     * This field was generated by MyBatis Generator.\n     * This field corresponds to the database column user_info.id\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    private String id;\n\n    /**\n     * This field was generated by MyBatis Generator.\n     * This field corresponds to the database column user_info.username\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    private String username;\n\n    /**\n     * This field was generated by MyBatis Generator.\n     * This field corresponds to the database column user_info.net_name\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    private String netName;\n\n    /**\n     * This field was generated by MyBatis Generator.\n     * This field corresponds to the database column user_info.job\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    private String job;\n\n    /**\n     * This field was generated by MyBatis Generator.\n     * This field corresponds to the database column user_info.family_native_place\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    private String familyNativePlace;\n\n    /**\n     * This field was generated by MyBatis Generator.\n     * This field corresponds to the database column user_info.mobile\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    private String mobile;\n\n    /**\n     * This field was generated by MyBatis Generator.\n     * This field corresponds to the database column user_info.email\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    private String email;\n\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method returns the value of the database column user_info.id\n     *\n     * @return the value of user_info.id\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    public String getId() {\n        return id;\n    }\n\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method sets the value of the database column user_info.id\n     *\n     * @param id the value for user_info.id\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    public void setId(String id) {\n        this.id = id;\n    }\n\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method returns the value of the database column user_info.username\n     *\n     * @return the value of user_info.username\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    public String getUsername() {\n        return username;\n    }\n\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method sets the value of the database column user_info.username\n     *\n     * @param username the value for user_info.username\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    public void setUsername(String username) {\n        this.username = username;\n    }\n\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method returns the value of the database column user_info.net_name\n     *\n     * @return the value of user_info.net_name\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    public String getNetName() {\n        return netName;\n    }\n\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method sets the value of the database column user_info.net_name\n     *\n     * @param netName the value for user_info.net_name\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    public void setNetName(String netName) {\n        this.netName = netName;\n    }\n\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method returns the value of the database column user_info.job\n     *\n     * @return the value of user_info.job\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    public String getJob() {\n        return job;\n    }\n\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method sets the value of the database column user_info.job\n     *\n     * @param job the value for user_info.job\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    public void setJob(String job) {\n        this.job = job;\n    }\n\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method returns the value of the database column user_info.family_native_place\n     *\n     * @return the value of user_info.family_native_place\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    public String getFamilyNativePlace() {\n        return familyNativePlace;\n    }\n\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method sets the value of the database column user_info.family_native_place\n     *\n     * @param familyNativePlace the value for user_info.family_native_place\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    public void setFamilyNativePlace(String familyNativePlace) {\n        this.familyNativePlace = familyNativePlace;\n    }\n\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method returns the value of the database column user_info.mobile\n     *\n     * @return the value of user_info.mobile\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    public String getMobile() {\n        return mobile;\n    }\n\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method sets the value of the database column user_info.mobile\n     *\n     * @param mobile the value for user_info.mobile\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    public void setMobile(String mobile) {\n        this.mobile = mobile;\n    }\n\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method returns the value of the database column user_info.email\n     *\n     * @return the value of user_info.email\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    public String getEmail() {\n        return email;\n    }\n\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method sets the value of the database column user_info.email\n     *\n     * @param email the value for user_info.email\n     *\n     * @mbggenerated Fri May 27 01:50:31 CST 2016\n     */\n    public void setEmail(String email) {\n        this.email = email;\n    }\n}"
  },
  {
    "path": "src/main/java/com/huan/service/CommonService.java",
    "content": "package com.huan.service;\n\nimport com.huan.model.UserDetail;\nimport com.huan.model.UserInfo;\n\nimport java.util.List;\n\n/**\n * @author <a href=\"mailto:huanhuan.zhan@ptthink.com\">詹欢欢</a>\n * @since 2016/7/5 - 22:20\n */\npublic interface CommonService {\n    List<UserInfo> selectUserInfo();\n\n    List<UserDetail> selectUserDetail();\n}\n"
  },
  {
    "path": "src/main/java/com/huan/service/Test1Service.java",
    "content": "package com.huan.service;\n\nimport com.huan.model.UserInfo;\n\nimport java.util.List;\n\n/**\n * @author <a href=\"mailto:huanhuan.zhan@ptthink.com\">詹欢欢</a>\n * @since 2016/7/5 - 22:18\n */\npublic interface Test1Service {\n\n    List<UserInfo> selectUserInfo();\n}\n"
  },
  {
    "path": "src/main/java/com/huan/service/Test2Service.java",
    "content": "package com.huan.service;\n\nimport com.huan.model.UserDetail;\n\nimport java.util.List;\n\n/**\n * @author <a href=\"mailto:huanhuan.zhan@ptthink.com\">詹欢欢</a>\n * @since 2016/7/5 - 22:21\n */\npublic interface Test2Service {\n\n    List<UserDetail> selectUserDetail();\n}\n"
  },
  {
    "path": "src/main/java/com/huan/service/impl/CommonServiceImpl.java",
    "content": "package com.huan.service.impl;\n\nimport com.huan.model.UserDetail;\nimport com.huan.model.UserInfo;\nimport com.huan.service.CommonService;\nimport com.huan.service.Test1Service;\nimport com.huan.service.Test2Service;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Service;\n\nimport java.util.List;\n\n/**\n * @author <a href=\"mailto:huanhuan.zhan@ptthink.com\">詹欢欢</a>\n * @since 2016/7/5 - 22:20\n */\n@Service\npublic class CommonServiceImpl implements CommonService {\n\n    @Autowired\n    private Test1Service test1Service;\n    @Autowired\n    private Test2Service test2Service;\n\n    public List<UserInfo> selectUserInfo() {\n        return test1Service.selectUserInfo();\n    }\n\n    public List<UserDetail> selectUserDetail() {\n        return test2Service.selectUserDetail();\n    }\n}\n"
  },
  {
    "path": "src/main/java/com/huan/service/impl/Test1ServiceImpl.java",
    "content": "package com.huan.service.impl;\n\nimport com.huan.mapper.UserInfoMapper;\nimport com.huan.model.UserInfo;\nimport com.huan.service.Test1Service;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Service;\n\nimport java.util.List;\n\n@Service\npublic class Test1ServiceImpl implements Test1Service {\n\n    @Autowired\n    private UserInfoMapper userInfoMapper;\n\n    public List<UserInfo> selectUserInfo() {\n        return userInfoMapper.selectAll();\n    }\n}"
  },
  {
    "path": "src/main/java/com/huan/service/impl/Test2ServiceImpl.java",
    "content": "package com.huan.service.impl;\n\nimport com.huan.mapper.UserDetailMapper;\nimport com.huan.model.UserDetail;\nimport com.huan.service.Test2Service;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Service;\n\nimport java.util.List;\n\n/**\n * @author <a href=\"mailto:huanhuan.zhan@ptthink.com\">詹欢欢</a>\n * @since 2016/7/5 - 22:21\n */\n@Service\npublic class Test2ServiceImpl implements Test2Service {\n\n    @Autowired\n    private UserDetailMapper userDetailMapper;\n\n    public List<UserDetail> selectUserDetail() {\n        return userDetailMapper.selectAll();\n    }\n}\n"
  },
  {
    "path": "src/main/java/com/huan/util/Constants.java",
    "content": "package com.huan.util;\n\n/**\n * @author <a href=\"mailto:jean@eastcode.org\">Jean Seurin</a>\n * @version $Id$\n * @since 13/08/15 - 18:36\n */\npublic class Constants {\n\n    public static final boolean DEBUG = true;\n    public static final String DATA_ENCODE = \"utf-8\";\n\n    public static final String JSON_VIEW_STATUS_SUCCESS = \"success\";\n    public static final String JSON_VIEW_STATUS_FAILED = \"failed\";\n    public static final String JSON_VIEW_STATUS_ERROR = \"error\";\n    public static final String JSON_VIEW_STATUS_UNAUTHORIZED = \"unauthorized\";\n\n    public static final String SPRING_PROFILE_PRODUCTION = \"prod\";\n    public static final String SPRING_PROFILE_DEVELOPMENT = \"dev\";\n    public static final String SPRING_PROFILE_TEST = \"test\";\n    public static final String SPRING_PROFILE_FAST = \"fast\";\n    public static final String SPRING_PROFILE_JSE = \"jse\";\n    public static final String SPRING_PROFILE_STAGING = \"staging\";\n\n    public static final String LOCAL_SERVER_URL = \"http://localhost:8080\";\n}\n"
  },
  {
    "path": "src/main/java/com/huan/util/DatabaseContextHolder.java",
    "content": "package com.huan.util;\n\n/**\n * 作用：\n * 1、保存一个线程安全的DatabaseType容器\n */\npublic class DatabaseContextHolder {\n    private static final ThreadLocal<DatabaseType> contextHolder = new ThreadLocal<>();\n\n    public static DatabaseType getDatabaseType(){\n        return contextHolder.get();\n    }\n\n    public static void setDatabaseType(DatabaseType type) {\n        contextHolder.set(type);\n    }\n}"
  },
  {
    "path": "src/main/java/com/huan/util/DatabaseType.java",
    "content": "package com.huan.util;\n\n/**\n * 列出所有的数据源key（常用数据库名称来命名）\n * 注意：\n * 1）这里数据源与数据库是一对一的\n * 2）DatabaseType中的变量名称就是数据库的名称\n */\npublic enum DatabaseType {\n    test1,\n    test2\n}"
  },
  {
    "path": "src/main/java/com/huan/util/DynamicDataSource.java",
    "content": "package com.huan.util;\n\nimport org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;\n\n/**\n * 动态数据源（需要继承AbstractRoutingDataSource）\n */\npublic class DynamicDataSource extends AbstractRoutingDataSource {\n    protected Object determineCurrentLookupKey() {\n        return DatabaseContextHolder.getDatabaseType();\n    }\n}"
  },
  {
    "path": "src/main/resources/application.yml",
    "content": "server:\n    port: 8080\n\ntest1-datasource:\n    driverClassName: com.mysql.jdbc.Driver\n    url: jdbc:mysql://localhost:3306/database1?characterEncoding=utf8&useSSL=false&serverTimezone=UTC\n    username: root\n    password: root\ntest2-datasource:\n    driverClassName: com.mysql.jdbc.Driver\n    url: jdbc:mysql://localhost:3306/database2?characterEncoding=utf8&useSSL=false&serverTimezone=UTC\n    username: root\n    password: root\n"
  },
  {
    "path": "src/main/resources/database1.sql",
    "content": "/*\nSQLyog Ultimate v11.27 (32 bit)\nMySQL - 5.6.27-log : Database - database1\n*********************************************************************\n*/\n\n\n/*!40101 SET NAMES utf8 */;\n\n/*!40101 SET SQL_MODE = '' */;\n\n/*!40014 SET @OLD_UNIQUE_CHECKS = @@UNIQUE_CHECKS, UNIQUE_CHECKS = 0 */;\n/*!40014 SET @OLD_FOREIGN_KEY_CHECKS = @@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS = 0 */;\n/*!40101 SET @OLD_SQL_MODE = @@SQL_MODE, SQL_MODE = 'NO_AUTO_VALUE_ON_ZERO' */;\n/*!40111 SET @OLD_SQL_NOTES = @@SQL_NOTES, SQL_NOTES = 0 */;\nCREATE DATABASE /*!32312 IF NOT EXISTS */`database1` /*!40100 DEFAULT CHARACTER SET utf8 */;\n\nUSE `database1`;\n\n/*Table structure for table `user_info` */\n\nDROP TABLE IF EXISTS `user_info`;\n\nCREATE TABLE `user_info` (\n  `id`                  VARCHAR(100) NOT NULL,\n  `username`            VARCHAR(255) DEFAULT NULL,\n  `net_name`            VARCHAR(255) DEFAULT NULL,\n  `job`                 VARCHAR(255) DEFAULT NULL,\n  `family_native_place` VARCHAR(255) DEFAULT NULL,\n  `mobile`              VARCHAR(100) DEFAULT NULL,\n  `email`               VARCHAR(255) DEFAULT NULL,\n  PRIMARY KEY (`id`)\n)\n  ENGINE = InnoDB\n  DEFAULT CHARSET = utf8;\n\n/*Data for the table `user_info` */\n\nINSERT INTO `user_info` (`id`, `username`, `net_name`, `job`, `family_native_place`, `mobile`, `email`)\nVALUES ('1', '詹欢欢', 'heikehuan', 'java后端开发', '湖北省孝感市', '15010699876', '873089996@qq.com');\n\n/*!40101 SET SQL_MODE = @OLD_SQL_MODE */;\n/*!40014 SET FOREIGN_KEY_CHECKS = @OLD_FOREIGN_KEY_CHECKS */;\n/*!40014 SET UNIQUE_CHECKS = @OLD_UNIQUE_CHECKS */;\n/*!40111 SET SQL_NOTES = @OLD_SQL_NOTES */;\n"
  },
  {
    "path": "src/main/resources/database2.sql",
    "content": "/*\r\nSQLyog Ultimate v11.27 (32 bit)\r\nMySQL - 5.6.27-log : Database - database2\r\n*********************************************************************\r\n*/\r\r\n\r\n/*!40101 SET NAMES utf8 */;\r\n\r\n/*!40101 SET SQL_MODE=''*/;\r\n\r\n/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\r\n/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\r\n/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\r\n/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\r\nCREATE DATABASE /*!32312 IF NOT EXISTS*/`database2` /*!40100 DEFAULT CHARACTER SET utf8 */;\r\n\r\nUSE `database2`;\r\n\r\n/*Table structure for table `user_detail` */\r\n\r\nDROP TABLE IF EXISTS `user_detail`;\r\n\r\nCREATE TABLE `user_detail` (\r\n  `id` bigint(20) NOT NULL,\r\n  `name` varchar(255) DEFAULT NULL,\r\n  `qq` varchar(255) DEFAULT NULL,\r\n  PRIMARY KEY (`id`)\r\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\r\n\r\n/*Data for the table `user_detail` */\r\n\r\ninsert  into `user_detail`(`id`,`name`,`qq`) values (1,'lululu','1231231');\r\n\r\n/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\r\n/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\r\n/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\r\n/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\r\n"
  },
  {
    "path": "src/main/resources/generator/generatorConfig.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<!DOCTYPE generatorConfiguration\n        PUBLIC \"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN\"\n        \"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd\">\n\n<generatorConfiguration>\n    <properties resource=\"generator/mybatis_generator_config.properties\"/>\n\n    <context id=\"Mysql\" targetRuntime=\"MyBatis3Simple\" defaultModelType=\"flat\">\n        <property name=\"beginningDelimiter\" value=\"`\"/>\n        <property name=\"endingDelimiter\" value=\"`\"/>\n\n        <plugin type=\"${mapper.plugin}\">\n            <property name=\"mappers\" value=\"${mapper.Mapper}\"/>\n        </plugin>\n\n        <jdbcConnection driverClass=\"${jdbc.driverClass}\"\n                        connectionURL=\"${jdbc.url}\"\n                        userId=\"${jdbc.user}\"\n                        password=\"${jdbc.password}\">\n        </jdbcConnection>\n\n        <javaModelGenerator targetPackage=\"${targetModelPackage}\" targetProject=\"${targetJavaProject}\"/>\n\n        <sqlMapGenerator targetPackage=\"${targetXMLPackage}\" targetProject=\"${targetResourcesProject}\"/>\n\n        <javaClientGenerator targetPackage=\"${targetMapperPackage}\" targetProject=\"${targetJavaProject}\"\n                             type=\"XMLMAPPER\"/>\n\n        <table tableName=\"%\">\n            <generatedKey column=\"id\" sqlStatement=\"Mysql\" identity=\"true\"/>\n        </table>\n    </context>\n</generatorConfiguration>\n"
  },
  {
    "path": "src/main/resources/generator/mybatis_generator_config.properties",
    "content": "#数据库连接\njdbc.driverClass = com.mysql.jdbc.Driver\njdbc.url =jdbc\\:mysql\\://localhost\\:3306/huan_blog_test?useUnicode\\=true&characterEncoding\\=utf8\njdbc.user=root\njdbc.password=root\n\n#c3p0\njdbc.maxPoolSize=50\njdbc.minPoolSize=10\njdbc.maxStatements=100\njdbc.testConnection=true\n\n# 通用mapper\nmapper.plugin = tk.mybatis.mapper.generator.MapperPlugin\nmapper.Mapper = tk.mybatis.mapper.common.Mapper\n"
  },
  {
    "path": "src/main/resources/logback.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<configuration>\n\n    <appender name=\"STDOUT\" class=\"ch.qos.logback.core.ConsoleAppender\">\n        <layout class=\"ch.qos.logback.classic.PatternLayout\">\n            <Pattern>\n                %d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n\n            </Pattern>\n        </layout>\n    </appender>\n\n    <logger name=\"org.springframework\" level=\"debug\" additivity=\"false\">\n        <appender-ref ref=\"STDOUT\"/>\n    </logger>\n\n    <logger name=\"com.huan\" level=\"debug\" additivity=\"false\">\n        <appender-ref ref=\"STDOUT\"/>\n    </logger>\n\n    <root level=\"error\">\n        <appender-ref ref=\"STDOUT\"/>\n    </root>\n\n</configuration>"
  },
  {
    "path": "src/main/resources/mapper/UserDetailMapper.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\" >\n<mapper namespace=\"com.huan.mapper.UserDetailMapper\">\n    <resultMap id=\"BaseResultMap\" type=\"com.huan.model.UserDetail\">\n        <!--\n          WARNING - @mbggenerated\n        -->\n        <id column=\"id\" property=\"id\" jdbcType=\"BIGINT\"/>\n        <result column=\"name\" property=\"name\" jdbcType=\"VARCHAR\"/>\n        <result column=\"qq\" property=\"qq\" jdbcType=\"VARCHAR\"/>\n    </resultMap>\n</mapper>"
  },
  {
    "path": "src/main/resources/mapper/UserInfoMapper.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\" >\n<mapper namespace=\"com.huan.mapper.UserInfoMapper\">\n  <resultMap id=\"BaseResultMap\" type=\"com.huan.model.UserInfo\">\n    <!--\n      WARNING - @mbggenerated\n      This element is automatically generated by MyBatis Generator, do not modify.\n      This element was generated on Fri May 27 01:50:31 CST 2016.\n    -->\n    <id column=\"id\" property=\"id\" jdbcType=\"VARCHAR\"/>\n    <result column=\"username\" property=\"username\" jdbcType=\"VARCHAR\"/>\n    <result column=\"net_name\" property=\"netName\" jdbcType=\"VARCHAR\"/>\n    <result column=\"job\" property=\"job\" jdbcType=\"VARCHAR\"/>\n    <result column=\"family_native_place\" property=\"familyNativePlace\" jdbcType=\"VARCHAR\"/>\n    <result column=\"mobile\" property=\"mobile\" jdbcType=\"VARCHAR\"/>\n    <result column=\"email\" property=\"email\" jdbcType=\"VARCHAR\"/>\n  </resultMap>\n  <delete id=\"deleteByPrimaryKey\" parameterType=\"java.lang.String\">\n    <!--\n      WARNING - @mbggenerated\n      This element is automatically generated by MyBatis Generator, do not modify.\n      This element was generated on Fri May 27 01:50:31 CST 2016.\n    -->\n    delete from user_info\n    where id = #{id,jdbcType=VARCHAR}\n  </delete>\n  <insert id=\"insert\" parameterType=\"com.huan.model.UserInfo\">\n    <!--\n      WARNING - @mbggenerated\n      This element is automatically generated by MyBatis Generator, do not modify.\n      This element was generated on Fri May 27 01:50:31 CST 2016.\n    -->\n    <selectKey resultType=\"java.lang.String\" keyProperty=\"id\" order=\"AFTER\">\n      SELECT LAST_INSERT_ID()\n    </selectKey>\n    insert into user_info (username, net_name, job,\n    family_native_place, mobile, email\n    )\n    values (#{username,jdbcType=VARCHAR}, #{netName,jdbcType=VARCHAR}, #{job,jdbcType=VARCHAR},\n    #{familyNativePlace,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}\n    )\n  </insert>\n  <update id=\"updateByPrimaryKey\" parameterType=\"com.huan.model.UserInfo\">\n    <!--\n      WARNING - @mbggenerated\n      This element is automatically generated by MyBatis Generator, do not modify.\n      This element was generated on Fri May 27 01:50:31 CST 2016.\n    -->\n    update user_info\n    set username = #{username,jdbcType=VARCHAR},\n      net_name = #{netName,jdbcType=VARCHAR},\n      job = #{job,jdbcType=VARCHAR},\n      family_native_place = #{familyNativePlace,jdbcType=VARCHAR},\n      mobile = #{mobile,jdbcType=VARCHAR},\n      email = #{email,jdbcType=VARCHAR}\n    where id = #{id,jdbcType=VARCHAR}\n  </update>\n  <select id=\"selectByPrimaryKey\" resultMap=\"BaseResultMap\" parameterType=\"java.lang.String\">\n    <!--\n      WARNING - @mbggenerated\n      This element is automatically generated by MyBatis Generator, do not modify.\n      This element was generated on Fri May 27 01:50:31 CST 2016.\n    -->\n    select id, username, net_name, job, family_native_place, mobile, email\n    from user_info\n    where id = #{id,jdbcType=VARCHAR}\n  </select>\n  <select id=\"selectAll\" resultMap=\"BaseResultMap\">\n    <!--\n      WARNING - @mbggenerated\n      This element is automatically generated by MyBatis Generator, do not modify.\n      This element was generated on Fri May 27 01:50:31 CST 2016.\n    -->\n    select id, username, net_name, job, family_native_place, mobile, email\n    from user_info\n  </select>\n</mapper>"
  }
]