feat: 分库分表

This commit is contained in:
胥员员 2022-11-05 21:42:29 +08:00
parent e0d76a3bf9
commit ca6e8eff22
9 changed files with 186 additions and 0 deletions

View File

@ -0,0 +1,15 @@
package com.yupi.project.mapper;
import com.yupi.project.model.entity.OrderConfigDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* @author Administrator
*/
@Mapper
public interface OrderConfigMapper {
OrderConfigDO selectById(@Param("id") Integer id);
}

View File

@ -0,0 +1,12 @@
package com.yupi.project.mapper;
import com.yupi.project.model.entity.OrderDO;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface OrderMapper {
void insert(OrderDO order);
}

View File

@ -0,0 +1,25 @@
package com.yupi.project.model.entity;
import lombok.Data;
import java.io.Serializable;
/**
* 订单配置 DO
*/
@Data
public class OrderConfigDO implements Serializable {
/**
* 编号
*/
private Integer id;
/**
* 支付超时时间
*
* 单位分钟
*/
private Integer payTimeout;
// ... 省略 setting/getting 方法
}

View File

@ -0,0 +1,23 @@
package com.yupi.project.model.entity;
import lombok.Data;
import java.io.Serializable;
/**
* 订单 DO
* @author Administrator
*/
@Data
public class OrderDO implements Serializable {
/**
* 订单编号
*/
private Long id;
/**
* 用户编号
*/
private Integer userId;
}

View File

@ -0,0 +1,22 @@
<?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="com.yupi.project.mapper.OrderConfigMapper">
<resultMap id="BaseResultMap" type="com.yupi.project.model.entity.OrderConfigDO">
<id property="id" column="id" jdbcType="INTEGER"/>
<id property="payTimeout" column="pay_timeout" jdbcType="INTEGER"/>
</resultMap>
<sql id="FIELDS">
id, pay_timeout
</sql>
<select id="selectById" parameterType="Integer" resultMap="BaseResultMap">
SELECT
<include refid="FIELDS" />
FROM order_config
WHERE id = #{id}
</select>
</mapper>

View File

@ -0,0 +1,15 @@
<?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="com.yupi.project.mapper.OrderMapper">
<resultMap id="BaseResultMap" type="com.yupi.project.model.entity.OrderDO">
<id property="userId" column="user_id" jdbcType="INTEGER"/>
</resultMap>
<insert id="insert" parameterType="OrderDO" useGeneratedKeys="true" keyProperty="id">
INSERT INTO orders (id, user_id)
VALUES (#{id}, #{userId})
</insert>
</mapper>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 使用驼峰命名法转换字段。 -->
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
<typeAliases>
<typeAlias alias="Integer" type="java.lang.Integer"/>
<typeAlias alias="Long" type="java.lang.Long"/>
<typeAlias alias="HashMap" type="java.util.HashMap"/>
<typeAlias alias="LinkedHashMap" type="java.util.LinkedHashMap"/>
<typeAlias alias="ArrayList" type="java.util.ArrayList"/>
<typeAlias alias="LinkedList" type="java.util.LinkedList"/>
</typeAliases>
</configuration>

View File

@ -0,0 +1,26 @@
package com.yupi.project.service;
import com.yupi.project.mapper.OrderConfigMapper;
import com.yupi.project.model.entity.OrderConfigDO;
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;
@RunWith(SpringRunner.class)
@SpringBootTest
public class OrderConfigMapperTest {
@Autowired
private OrderConfigMapper orderConfigMapper;
@Test
public void testSelectById() {
OrderConfigDO orderConfig = orderConfigMapper.selectById(1);
System.out.println(orderConfig);
}
}

View File

@ -0,0 +1,28 @@
package com.yupi.project.service;
import com.yupi.project.mapper.OrderMapper;
import com.yupi.project.model.entity.OrderDO;
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;
@RunWith(SpringRunner.class)
@SpringBootTest
public class OrderMapperTest {
@Autowired
private OrderMapper orderMapper;
@Test
public void testInsert() {
OrderDO order = new OrderDO();
order.setId(2L);
order.setUserId(4);
orderMapper.insert(order);
}
}