<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    java隨記

    堅持就是勝利!

     

    springboot、mybatis、mycat分庫實踐

    1.pom文件中引入下面引入mybatis逆向工程插件
    <build>
    <plugins>
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
    <plugin>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-maven-plugin</artifactId>
    <version>1.3.4</version>
    <configuration>
    <verbose>true</verbose>
    <overwrite>true</overwrite>
    </configuration>
    </plugin>
    </plugins>
    </build>
       2, src/main/resource 目錄下引入mybatis逆向工程配置文件,這樣就可以自動生成mybatis需要的xml及dao interface
    <?xml version="1.0" encoding="UTF-8"?>
     <!DOCTYPE generatorConfiguration
       PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
       "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
     <generatorConfiguration>
         <!--數據庫驅動-->
         <classPathEntry    location="E:\\worksource\\springboot\\src\\main\\webapp\\WEB-INF\\lib\\mysql-connector-java-5.1.39.jar"/>
         <context id="DB2Tables"    targetRuntime="MyBatis3">
             <commentGenerator>
                 <property name="suppressDate" value="true"/>
                 <property name="suppressAllComments" value="true"/>
             </commentGenerator>
             <!--數據庫鏈接地址賬號密碼-->
             <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/jeeshop" userId="root" password="">
             </jdbcConnection>
             <javaTypeResolver>
                 <property name="forceBigDecimals" value="false"/>
             </javaTypeResolver>
             <!--生成Model類存放位置-->
             <javaModelGenerator targetPackage="com.junjun.myblog.domain" targetProject="src/main/java">
                 <property name="enableSubPackages" value="true"/>
                 <property name="trimStrings" value="true"/>
             </javaModelGenerator>
             <!--生成映射文件存放位置-->
             <sqlMapGenerator targetPackage="src/main/resources/mapper" targetProject=".">
                 <property name="enableSubPackages" value="true"/>
             </sqlMapGenerator>
             <!--生成Dao類存放位置-->
             <javaClientGenerator type="XMLMAPPER" targetPackage="com.junjun.myblog.dao" targetProject="src/main/java">
                 <property name="enableSubPackages" value="true"/>
             </javaClientGenerator>
             <!--生成對應表及類名 mapperName="AreaDao"  工程右鍵 Debug As -> maven build... -> mybatis-generator:generate
             <table tableName="t_area"   domainObjectName="Area" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        -->
    </context>
     </generatorConfiguration>
    3,application 中加上注解  @MapperScan("com.junjun") 
    4,數據源連接mycat
    spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
    spring.datasource.driver-class-name=com.mysql.jdbc.Driver
    spring.datasource.url=jdbc:mysql://localhost:8066/MYSQL?useUnicode=true&characterEncoding=UTF-8
    spring.datasource.username=root
    spring.datasource.password=123456
    二,mycat配置
    1,conf/server.xml中配置用戶 和schema
    <user name="root">
    <property name="password">123456</property>
    <property name="schemas">MYSQL</property>
    </user>
    2,schema.xml配置數據庫和分片表分片規則
    <schema name="MYSQL" checkSQLschema="false" sqlMaxLimit="100">
    <table name="t_blogger" primaryKey="id" dataNode="dn1" >     </table> 
    <!--按需配置分片規則-->
            <table name="t_area" primaryKey="id" dataNode="dn1,dn2,dn3" rule="mod-long1">     </table> 
    <table name="t_blog" primaryKey="id" dataNode="dn1" >     </table> 
    <table name="t_blogtype" primaryKey="id" dataNode="dn1" >     </table> 
    </schema>
    <!-- <dataNode name="dn1$0-743" dataHost="localhost1" database="db$0-743"
    /> -->
    <dataNode name="dn1" dataHost="localhost1" database="jeeshop" />
    <dataNode name="dn2" dataHost="localhost2" database="jysystem" />
    <dataNode name="dn3" dataHost="localhost3" database="dn3" />
    <!--<dataNode name="dn4" dataHost="sequoiadb1" database="SAMPLE" />
    <dataNode name="jdbc_dn1" dataHost="jdbchost" database="db1" />
    <dataNode name="jdbc_dn2" dataHost="jdbchost" database="db2" />
    <dataNode name="jdbc_dn3" dataHost="jdbchost" database="db3" /> -->
    <dataHost name="localhost1" maxCon="1000" minCon="10" balance="0"
      writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
    <heartbeat>select user()</heartbeat>
    <!-- can have multi write hosts -->
    <writeHost host="hostM1" url="localhost:3306" user="root"
       password="">
    <!-- can have multi read hosts 
    <readHost host="hostS2" url="192.168.1.200:3306" user="root" password="" /> -->
    </writeHost>
    <!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
    </dataHost>
    <dataHost name="localhost2" maxCon="1000" minCon="10" balance="0"
      writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
    <heartbeat>select user()</heartbeat>
    <!-- can have multi write hosts -->
    <writeHost host="hostM2" url="127.0.0.1:3306" user="root"
       password="">
    <!-- can have multi read hosts 
    <readHost host="hostS2" url="192.168.1.200:3306" user="root" password="" /> -->
    </writeHost>
    <!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
    </dataHost>
    <dataHost name="localhost3" maxCon="1000" minCon="10" balance="0"
      writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
    <heartbeat>select user()</heartbeat>
    <!-- can have multi write hosts -->
    <writeHost host="hostM2" url="127.0.0.1:3306" user="root"
       password="">
    <!-- can have multi read hosts 
    <readHost host="hostS2" url="192.168.1.200:3306" user="root" password="" /> -->
    </writeHost>
    <!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
    </dataHost>
    3,rule.xml配置分片規則
        添加如下規則 按表的name字段進行分片存儲
    <tableRule name="mod-long1">
    <rule>
    <columns>name</columns>
    <algorithm>mod-long</algorithm>
    </rule>
    </tableRule>
    備注:內容太多,記一下重點. 分庫后連接查詢不在同一個庫是查不到數據的,真有這需要那就真需要考慮
    設計是否合理了.

    posted on 2017-10-01 17:40 傻 瓜 閱讀(5098) 評論(0)  編輯  收藏 所屬分類: 雜項

    導航

    統計

    常用鏈接

    留言簿(7)

    我參與的團隊

    隨筆分類

    隨筆檔案

    文章分類

    友情鏈接

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲伊人久久大香线蕉在观| 亚洲人成亚洲精品| 激情小说亚洲色图| 成年女性特黄午夜视频免费看| 亚洲av色影在线| 88xx成人永久免费观看| 婷婷亚洲综合五月天小说| a级午夜毛片免费一区二区| 国产亚洲av片在线观看18女人| 一级毛片无遮挡免费全部| 久久激情亚洲精品无码?V| 亚洲五月午夜免费在线视频| 亚洲国产精品毛片av不卡在线| 日本永久免费a∨在线视频| 亚洲国产精品无码久久久久久曰| 四虎精品成人免费视频| 亚洲乱亚洲乱妇无码麻豆| 毛片免费在线观看| 亚洲福利一区二区三区| 女人与禽交视频免费看| 国产成人亚洲精品91专区高清| 久久久久亚洲精品天堂久久久久久 | 国产精品爱啪在线线免费观看| 亚洲综合综合在线| 成人免费毛片内射美女APP | 新最免费影视大全在线播放| 狠狠色婷婷狠狠狠亚洲综合| av永久免费网站在线观看| 亚洲视频在线观看网站| 四虎在线免费播放| 中文字幕在线观看免费| 亚洲最大免费视频网| 免费看又爽又黄禁片视频1000| 青青青视频免费观看| 亚洲高清美女一区二区三区| 成人免费无码大片a毛片软件| 免费毛片毛片网址| 亚洲激情视频在线观看| 国产免费久久精品久久久| 久久国产精品国产自线拍免费| 亚洲18在线天美|