Sharding-JDBC从入门到精通(4)- Sharding-JDBC 入门程序几种配置方式
一、Sharding-JDBC 入门程序(水平分表)-使用 application.yml 配置文件的 方式
1、打开 idea 创建 artifactId 名为 dbsharding 的 maven 父工程。
--> idea --> File --> New --> Project --> Maven Project SDK: ( 1.8(java version "1.8.0_131" ) --> Next --> Groupld : ( djh.it )Artifactld : ( dbsharding )Version : 1.0-SNAPSHOT--> Name: ( dbsharding )Location: ( ...\dbsharding\ ) --> Finish
2、在 dbsharding 父工程的 pom.xml 文件中导入依赖坐标。
<?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>djh.it</groupId><artifactId>dbsharding</artifactId><packaging>pom</packaging><version>1.0-SNAPSHOT</version><modules><module>sharding_jdbc_simple</module></modules><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.3.RELEASE</version></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><dependencyManagement><dependencies><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.9.2</version></dependency><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>2.9.2</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.0</version></dependency><dependency><groupId>javax.interceptor</groupId><artifactId>javax.interceptor-api</artifactId><version>1.2</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.46</version></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.0.0</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.1.16</version></dependency><dependency><groupId>org.apache.shardingsphere</groupId><artifactId>sharding-jdbc-spring-boot-starter</artifactId><version>4.0.0-RC1</version></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.1.0</version></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-generator</artifactId><version>3.1.0</version></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-typehandlers-jsr310</artifactId><version>1.0.2</version></dependency></dependencies></dependencyManagement></project>
<!-- ...\dbsharding\pom.xml -->
3、打开 idea 创建 artifactId 名为 sharding_jdbc_simple 的 maven 子工程(子模块)。
--> idea --> 右键 dbsharding 父工程 --> New --> Module...--> Maven Project SDK: ( 1.8(java version "1.8.0_131" ) --> Next --> Groupld : ( djh.it )Artifactld : ( sharding_jdbc_simple )Version : 1.0-SNAPSHOT--> Module Name: ( sharding_jdbc_simple )Content root: ( ...\dbsharding\sharding_jdbc_simple )Module file location: ( ...\dbsharding\sharding_jdbc_simple ) --> Finish
4、在 sharding_jdbc_simple 子工程(子模块)的 pom.xml 文件中导入依赖坐标。
<?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"><parent><artifactId>dbsharding</artifactId><groupId>djh.it</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>sharding_jdbc_simple</artifactId><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><dependency><groupId>org.apache.shardingsphere</groupId><artifactId>sharding-jdbc-spring-boot-starter</artifactId></dependency></dependencies></project>
<!-- ...\dbsharding\sharding_jdbc_simple\pom.xml -->
5、在 sharding_jdbc_simple 子工程(子模块)中,创建启动类 ShardingJdbcSimpleBootstrap.java。
/*** D:\Java\java-test\idea\dbsharding\sharding_jdbc_simple\src\main\java\djh\it\dbsharding\simple\ShardingJdbcSimpleBootstrap.java** 2024-6-28 创建启动类 ShardingJdbcSimpleBootstrap.java*/
package djh.it.dbsharding.simple;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class ShardingJdbcSimpleBootstrap {public static void main(String[] args) {SpringApplication.run(ShardingJdbcSimpleBootstrap.class, args);}
}
6、在 sharding_jdbc_simple 子工程(子模块)中,创建 application.yml 配置文件
# dbsharding\sharding_jdbc_simple\src\main\resources\application.ymlserver:port: 56081servlet:context-path: /sharding-jdbc-simple-demo
spring:application:name: sharding-jdbc-simple-demohttp:encoding:enabled: truecharset: utf-8force: truemain:allow-bean-definition-overriding: true# 配置 sharding-jdbc 分片规则# 定义数据源(定义数据源名为 m1)shardingsphere:datasource:names: m1m1:type: com.alibaba.druid.pool.DruidDataSource# driver-class-name: com.mysql.jdbc.DriverdriverClassName: com.mysql.jdbc.Driverurl: jdbc:mysql://localhost:3306/order_db?useUnicode=trueusername: rootpassword: 12311# 指定 t_order 表的数据分布情况,配置数据节点(t_order 映射到 t_order_1 或者 t_order_2)sharding:tables:t_order:# actual-data-nodes: m1.t_order_$->{1..2}actualDataNodes: m1.t_order_$->{1..2}# 指定 t_order 表的主键生成策略为 SNOWFLAKE(雪花算法)# key-generator:keyGenerator:column: order_idtype: SNOWFLAKE# 指定 t_order 表的分片策略,分片策略包括分片键和分片算法# table-strategy:tableStrategy:inline:# sharding-column: order_idshardingColumn: order_id# algorithm-expression: t_order_$->{order_id % 2 + 1}algorithmExpression: t_order_$->{order_id % 2 + 1}# 打开 sql 输出日志props:sql:show: true
swagger:enable: true
mybatis:configuration:map-underscore-to-camel-case: truelogging:level:root: infoorg:springframework:web: infodjh:it:dbsharding: debugdruid:sql: debug
7、在 sharding_jdbc_simple 子工程(子模块)中,创建 dao 接口类 OrderDao.java
/*** D:\Java\java-test\idea\dbsharding\sharding_jdbc_simple\src\main\java\djh\it\dbsharding\simple\dao\OrderDao.java** 2024-5-28 创建 dao 接口类 OrderDao.java*/
package djh.it.dbsharding.simple.dao;import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;import java.math.BigDecimal;
import java.util.List;
import java.util.Map;@Mapper
@Component
public interface OrderDao {//查询数据:根据订单ID ( SQL 语句:SELECT * FROM t_order_1 WHERE order_id IN (1013467489922711552, 1013467489960460288); )@Select( "<script>" +"select" +" * " +" from t_order t " +" where t.order_id in " +" <foreach collection=' orderIds' open='(' separator=',' close=')' item='id'>" +" #{id} " +" </foreach>" +"</script>" )List<Map> selectOrderByIds(@Param("orderIds") List<Long> orderIds);//插入数据@Insert("insert into t_order(price, user_id, status) values(#{price}, #{userId}, #{status})")int insertOrder(@Param("price") BigDecimal price, @Param("userId")Long userId, @Param("status")String status);
}
8、在 sharding_jdbc_simple 子工程(子模块)中,创建 接口 OrderDao 的测试类 testInsertOrder.java 进行测试
/*** dbsharding\sharding_jdbc_simple\src\test\java\djh\it\dbsharding\simple\dao\OrderDaoTest.java** 2024-6-28 创建 接口 OrderDao 的测试类 OrderDaoTest.java 进行测试** 快速生成 接口 OrderDao 类的测试类:* 1)右键 接口 OrderDao 选择 【Generate...】* 2)选择【Test..】* 3)Testing library : JUnit4* Class name : OrderDaoTest* SUPERCLASS : 空* Destination package : djh.it.dbsharding.simple.dao* 4)点击 OK。*/
package djh.it.dbsharding.simple.dao;import djh.it.dbsharding.simple.ShardingJdbcSimpleBootstrap;
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.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;@RunWith(SpringRunner.class)
@SpringBootTest(classes = {ShardingJdbcSimpleBootstrap.class})
public class OrderDaoTest {@AutowiredOrderDao orderDao;@Testpublic void testSelectOrderByIds(){List<Long> ids = new ArrayList<>();ids.add(1013467489922711552L); //此order_id 在 mysql 数据库的 t_order_1 表中,ids.add(1013465458055053313L); //此order_id 在 mysql 数据库的 t_order_2 表中,List<Map> maps = orderDao.selectOrderByIds(ids);System.out.println(maps);}@Testpublic void testInsertOrder(){//orderDao.insertOrder(new BigDecimal(11 ),1L, "SUCCESS");for(int i=1; i<20; i++){orderDao.insertOrder(new BigDecimal(i ),1L, "success2");}}
}
二、Sharding-JDBC 入门程序(水平分表)-集成 SpringBoot 方式
1、在 sharding_jdbc_simple 子工程(子模块)中,更改 application.yml 配置文件名为 application-bank.yml 使其失效。同时新创建 application.properties 配置文件。
# dbsharding\sharding_jdbc_simple\src\main\resources\application.propertiesserver.port = 56081spring.application.name = sharding-jdbc-simple-demoserver.servlet.context-path = /sharding-jdbc-simple-demo
spring.http.encoding.enabled = true
spring.http.encoding.charset = utf-8
spring.http.encoding.force = truespring.main.allow-bean-definition-overriding = true
mybatis.configuration.map-underscore-to-camel-case = trueswagger.enable = truelogging.level.root = info
logging.level.org.springframework.web = info
logging.level.djh.it.dbsharding = debug
logging.level.druid.sql = debug
2、在 sharding_jdbc_simple 子工程(子模块)中,创建 配置类 ShardingJdbcConfig.java
/**** D:\Java\java-test\idea\dbsharding\sharding_jdbc_simple\src\main\java\djh\it\dbsharding\simple\config\ShardingJdbcConfig.java** 2024-6-28 创建的配置类 ShardingJdbcConfig.java*/
package djh.it.dbsharding.simple.config;import com.alibaba.druid.pool.DruidDataSource;
import org.apache.shardingsphere.api.config.sharding.KeyGeneratorConfiguration;
import org.apache.shardingsphere.api.config.sharding.ShardingRuleConfiguration;
import org.apache.shardingsphere.api.config.sharding.TableRuleConfiguration;
import org.apache.shardingsphere.api.config.sharding.strategy.InlineShardingStrategyConfiguration;import org.apache.shardingsphere.shardingjdbc.api.ShardingDataSourceFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;@Configuration
public class ShardingJdbcConfig {//配置分片规则//定义数据源Map<String, DataSource> createDataSourceMap(){DruidDataSource dataSource = new DruidDataSource();dataSource.setDriverClassName("com.mysql.jdbc.Driver");;dataSource.setUrl("jdbc:mysql://localhost:3306/order_db?useUnicode=true");dataSource.setUsername("root");dataSource.setPassword("12311");Map<String, DataSource> result = new HashMap<>();result.put("m1", dataSource);return result;}//定义主键生成策略private static KeyGeneratorConfiguration getKeyGeneratorConfiguration(){KeyGeneratorConfiguration result = new KeyGeneratorConfiguration("SNOWFLAKE", "order_id");return result;}//定义 t_order 表的分片策略TableRuleConfiguration getOrderTableRuleConfiguration(){TableRuleConfiguration result = new TableRuleConfiguration("t_order", "m1.t_order_$->{1..2}");result.setTableShardingStrategyConfig(new InlineShardingStrategyConfiguration("order_id", "t_order_$->{order_id % 2 + 1 }" ));result.setKeyGeneratorConfig(getKeyGeneratorConfiguration());return result;}//定义 sharding-jdbc 数据源@BeanDataSource getShardingDataSource() throws SQLException {ShardingRuleConfiguration shardingRuleConfiguration = new ShardingRuleConfiguration();shardingRuleConfiguration.getTableRuleConfigs().add(getOrderTableRuleConfiguration());Properties properties = new Properties();properties.put("sql.show", "true");return ShardingDataSourceFactory.createDataSource(createDataSourceMap(), shardingRuleConfiguration, properties);}
}
3、在 sharding_jdbc_simple 子工程(子模块)中,修改启动类 添加 排除项
/*** dbsharding\sharding_jdbc_simple\src\main\java\djh\it\dbsharding\simple\ShardingJdbcSimpleBootstrap.java** 2024-6-28 创建启动类 ShardingJdbcSimpleBootstrap.java*/
package djh.it.dbsharding.simple;import org.apache.shardingsphere.shardingjdbc.spring.boot.SpringBootConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;//启动类添加 application.properties 配置文件 排除项,而是从 SpringBootConfiguration 配置文件加载。
@SpringBootApplication(exclude = SpringBootConfiguration.class)
public class ShardingJdbcSimpleBootstrap {public static void main(String[] args) {SpringApplication.run(ShardingJdbcSimpleBootstrap.class, args);}
}
4、sharding_jdbc_simple 子工程(子模块)中,dao 接口类 OrderDao.java
/*** D:\Java\java-test\idea\dbsharding\sharding_jdbc_simple\src\main\java\djh\it\dbsharding\simple\dao\OrderDao.java** 2024-5-28 创建 dao 接口类 OrderDao.java*/
package djh.it.dbsharding.simple.dao;import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;import java.math.BigDecimal;
import java.util.List;
import java.util.Map;@Mapper
@Component
public interface OrderDao {//查询数据:根据订单ID ( SQL 语句:SELECT * FROM t_order_1 WHERE order_id IN (1013467489922711552, 1013467489960460288); )@Select( "<script>" +"select" +" * " +" from t_order t " +" where t.order_id in " +" <foreach collection=' orderIds' open='(' separator=',' close=')' item='id'>" +" #{id} " +" </foreach>" +"</script>" )List<Map> selectOrderByIds(@Param("orderIds") List<Long> orderIds);//插入数据@Insert("insert into t_order(price, user_id, status) values(#{price}, #{userId}, #{status})")int insertOrder(@Param("price") BigDecimal price, @Param("userId")Long userId, @Param("status")String status);
}
5、sharding_jdbc_simple 子工程(子模块)中,测试类 OrderDaoTest.java 进行测试
/*** dbsharding\sharding_jdbc_simple\src\test\java\djh\it\dbsharding\simple\dao\OrderDaoTest.java** 2024-6-28 创建 接口 OrderDao 的测试类 OrderDaoTest.java 进行测试** 快速生成 接口 OrderDao 类的测试类:* 1)右键 接口 OrderDao 选择 【Generate...】* 2)选择【Test..】* 3)Testing library : JUnit4* Class name : OrderDaoTest* SUPERCLASS : 空* Destination package : djh.it.dbsharding.simple.dao* 4)点击 OK。*/
package djh.it.dbsharding.simple.dao;import djh.it.dbsharding.simple.ShardingJdbcSimpleBootstrap;
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.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;@RunWith(SpringRunner.class)
@SpringBootTest(classes = {ShardingJdbcSimpleBootstrap.class})
public class OrderDaoTest {@AutowiredOrderDao orderDao;@Testpublic void testSelectOrderByIds(){List<Long> ids = new ArrayList<>();ids.add(1013467489922711552L); //此order_id 在 t_order_1 表中,ids.add(1013465458055053313L); //此order_id 在 t_order_2 表中,List<Map> maps = orderDao.selectOrderByIds(ids);System.out.println(maps);}@Testpublic void testInsertOrder(){//orderDao.insertOrder(new BigDecimal(11 ),1L, "SUCCESS");for(int i=1; i<20; i++){orderDao.insertOrder(new BigDecimal(i ),1L, "success2");}}
}
三、Sharding-JDBC 入门程序(水平分表)- application.properties 配置文件 配置数据源 方式。
1、在 sharding_jdbc_simple 子工程(子模块)中,更改 application.properties 配置文件,添加数据源,同时删除 application.yml 配置文件 和 ShardingJdbcConfig.java 配置类。
# dbsharding\sharding_jdbc_simple\src\main\resources\application.propertiesserver.port = 56081spring.application.name = sharding-jdbc-simple-demoserver.servlet.context-path = /sharding-jdbc-simple-demo
spring.http.encoding.enabled = true
spring.http.encoding.charset = utf-8
spring.http.encoding.force = truespring.main.allow-bean-definition-overriding = true
mybatis.configuration.map-underscore-to-camel-case = true# 配置 sharding-jdbc 分片规则
# 定义数据源(定义数据源名为 m1)
spring.shardingsphere.datasource.names = m1spring.shardingsphere.datasource.m1.type = com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.m1.driver-class-name = com.mysql.jdbc.Driver
spring.shardingsphere.datasource.m1.url = jdbc:mysql://localhost:3306/order_db?useUnicode=true
spring.shardingsphere.datasource.m1.username = root
spring.shardingsphere.datasource.m1.password = 12311# 指定 t_order 表的数据分布情况,配置数据节点(t_order 映射到 t_order_1 或者 t_order_2)
spring.shardingsphere.sharding.tables.t_order.actual-data-nodes = m1.t_order_$->{1..2}# 指定 t_order 表的主键生成策略为 SNOWFLAKE(雪花算法)
spring.shardingsphere.sharding.tables.t_order.key-generator.column = order_id
spring.shardingsphere.sharding.tables.t_order.key-generator.type = SNOWFLAKE# 指定 t_order 表的分片策略,分片策略包括分片键和分片算法
spring.shardingsphere.sharding.tables.t_order.table-strategy.inline.sharding-column = order_id
spring.shardingsphere.sharding.tables.t_order.table-strategy.inline.algorithm-expression = t_order_$->{order_id % 2 + 1}# 打开 sql 输出日志
spring.shardingsphere.props.sql.show = trueswagger.enable = truelogging.level.root = info
logging.level.org.springframework.web = info
logging.level.djh.it.dbsharding = debug
logging.level.druid.sql = debug
2、sharding_jdbc_simple 子工程(子模块)中,启动类 ShardingJdbcSimpleBootstrap.java
/*** D:\Java\java-test\idea\dbsharding\sharding_jdbc_simple\src\main\java\djh\it\dbsharding\simple\ShardingJdbcSimpleBootstrap.java** 2024-6-28 创建启动类 ShardingJdbcSimpleBootstrap.java*/
package djh.it.dbsharding.simple;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;//启动类添加 application.properties 配置文件 排除项,而是从 SpringBootConfiguration 配置文件加载。
//@SpringBootApplication(exclude = SpringBootConfiguration.class)
//@ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,classes={SpringBootConfiguration.class})})
@SpringBootApplication
public class ShardingJdbcSimpleBootstrap {public static void main(String[] args) {SpringApplication.run(ShardingJdbcSimpleBootstrap.class, args);}
}
3、sharding_jdbc_simple 子工程(子模块)中,接口类 OrderDao.java
/*** D:\Java\java-test\idea\dbsharding\sharding_jdbc_simple\src\main\java\djh\it\dbsharding\simple\dao\OrderDao.java** 2024-5-28 创建 dao 接口类 OrderDao.java*/
package djh.it.dbsharding.simple.dao;import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;import java.math.BigDecimal;
import java.util.List;
import java.util.Map;@Mapper
@Component
public interface OrderDao {//查询数据:根据订单ID ( SQL 语句:SELECT * FROM t_order_1 WHERE order_id IN (1013467489922711552, 1013467489960460288); )@Select( "<script>" +"select" +" * " +" from t_order t " +" where t.order_id in " +" <foreach collection=' orderIds' open='(' separator=',' close=')' item='id'>" +" #{id} " +" </foreach>" +"</script>" )List<Map> selectOrderByIds(@Param("orderIds") List<Long> orderIds);//插入数据@Insert("insert into t_order(price, user_id, status) values(#{price}, #{userId}, #{status})")int insertOrder(@Param("price") BigDecimal price, @Param("userId")Long userId, @Param("status")String status);
}
4、sharding_jdbc_simple 子工程(子模块)中,接口 OrderDao 的测试类 OrderDaoTest.java 进行测试
/*** dbsharding\sharding_jdbc_simple\src\test\java\djh\it\dbsharding\simple\dao\OrderDaoTest.java** 2024-6-28 创建 接口 OrderDao 的测试类 OrderDaoTest.java 进行测试** 快速生成 接口 OrderDao 类的测试类:* 1)右键 接口 OrderDao 选择 【Generate...】* 2)选择【Test..】* 3)Testing library : JUnit4* Class name : OrderDaoTest* SUPERCLASS : 空* Destination package : djh.it.dbsharding.simple.dao* 4)点击 OK。*/
package djh.it.dbsharding.simple.dao;import djh.it.dbsharding.simple.ShardingJdbcSimpleBootstrap;
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.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;@RunWith(SpringRunner.class)
@SpringBootTest(classes = {ShardingJdbcSimpleBootstrap.class})
public class OrderDaoTest {@AutowiredOrderDao orderDao;@Testpublic void testSelectOrderByIds(){List<Long> ids = new ArrayList<>();ids.add(1013467489922711552L); //此order_id 在 t_order_1 表中,ids.add(1013465458055053313L); //此order_id 在 t_order_2 表中,List<Map> maps = orderDao.selectOrderByIds(ids);System.out.println(maps);}@Testpublic void testInsertOrder(){//orderDao.insertOrder(new BigDecimal(11 ),1L, "SUCCESS");for(int i=1; i<20; i++){orderDao.insertOrder(new BigDecimal(i ),1L, "success2");}}
}
上一节关联链接请点击
# Sharding-JDBC从入门到精通(3)- Sharding-JDBC 入门程序