时间:2021-07-01 10:21:17 帮助过:105人阅读
package com.sharding; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ImportResource; @SpringBootApplication @ImportResource("classpath*:sharding-jdbc.xml") @MapperScan("com.sharding.mapper") public class ShardingTest { public static void main(String[] args) { SpringApplication.run(ShardingTest.class); } }
package com.sharding.test; import com.sharding.mapper.OrderMapper; import com.sharding.pojo.vo.Order; 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 AppTest { @Autowired private OrderMapper orderMapper; @Test public void testInsert(){ Order order = new Order(); order.setId(10); order.setUserId(20); order.setAmount(200); order.setName("Test"); orderMapper.insert(order); } @Test public void testQuery(){ List<Order> test = orderMapper.getOrderByName("Test"); System.out.println("查询结果:" + test); } }
spring整合sharding-jdbc实现分库分表
标签:use sharp space his mybatis HERE tin engine ati