分库分表功能提交

This commit is contained in:
rice666
2023-06-27 23:40:52 +08:00
parent 9af2038efa
commit ed9c56d7ac
17 changed files with 870 additions and 5 deletions

View File

@@ -0,0 +1,16 @@
package org.dromara.demo.domain;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@TableName("t_order")
@Data
public class TOrder {
private Long orderId;
private Long userId;
private int totalMoney;
}

View File

@@ -0,0 +1,17 @@
package org.dromara.demo.domain;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@TableName("t_order_item")
@Data
public class TOrderItem {
private Long orderItemId;
private Long orderId;
private Long userId;
private int totalMoney;
}

View File

@@ -0,0 +1,12 @@
package org.dromara.demo.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.dromara.demo.domain.TOrderItem;
@Mapper
public interface TOrderItemMapper extends BaseMapper<TOrderItem> {
}

View File

@@ -0,0 +1,12 @@
package org.dromara.demo.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.dromara.demo.domain.TOrder;
@Mapper
public interface TOrderMapper extends BaseMapper<TOrder> {
}

View File

@@ -39,13 +39,19 @@ spring:
# 设置默认的数据源或者数据源组,默认值即为 master
primary: master
datasource:
# 主库数据源
master:
type: ${spring.datasource.type}
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: ${datasource.system-master.url}
username: ${datasource.system-master.username}
password: ${datasource.system-master.password}
url: jdbc:mysql://192.168.0.60:3307/data-center_db?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
username: root
password: root
# 主库数据源
# master:
# type: ${spring.datasource.type}
# driver-class-name: com.mysql.cj.jdbc.Driver
# url: ${datasource.system-master.url}
# username: ${datasource.system-master.username}
# password: ${datasource.system-master.password}
# oracle:
# type: ${spring.datasource.type}
# driverClassName: oracle.jdbc.OracleDriver

View File

@@ -0,0 +1,7 @@
<?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="org.dromara.demo.mapper.TOrderItemMapper">
</mapper>

View File

@@ -0,0 +1,7 @@
<?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="org.dromara.demo.mapper.TOrderMapper">
</mapper>

View File

@@ -0,0 +1,59 @@
package org.dromara.demo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.dromara.demo.domain.TOrder;
import org.dromara.demo.mapper.TOrderMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class TOrderTest {
@Autowired
TOrderMapper torderMapper;
//@Autowired
//TUserMapper userMapper;
@Test
void find() {
//Order order = orderMapper.selectById(1640990702722723841L);
}
@Test
void page() {
Page<TOrder> page = new Page<>();
page.setCurrent(3L);
QueryWrapper<TOrder> queryWrapper = new QueryWrapper<>();
queryWrapper.orderByAsc("order_id");
torderMapper.selectPage(page,queryWrapper);
System.out.println(page.getTotal());
for(TOrder order : page.getRecords()){
System.out.print(order.getTotalMoney()+" ");
}
}
@Test
void insert() {
for(Long i = 1L; i <= 100L; i++){
TOrder torder = new TOrder();
torder.setUserId(i);
torder.setTotalMoney(100 + Integer.parseInt(i+""));
torderMapper.insert(torder);
}
}
@Test
void insertUser() {
/*User user = new User();
user.setId(1L);
user.setUserName("abc");
user.setAge(18);
user.setCreateTime(new Date());
userMapper.insert(user);*/
}
}