Skip to content

修复 sharding datasource 01 sql 创建表失败的问题 #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ target/**

### IntelliJ IDEA
.idea
target
target
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ CREATE TABLE `order_config` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '编号',
`pay_timeout` int(11) DEFAULT NULL COMMENT '支付超时时间;单位:分钟',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

SET FOREIGN_KEY_CHECKS = 1;

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cn.iocoder.springboot.lab18.shardingdatasource.dataobject.OrderDO;
import cn.iocoder.springboot.lab18.shardingdatasource.mapper.OrderMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -22,7 +23,10 @@ public void add(OrderDO order) {
orderMapper.insert(order);

// 这里先假模假样的读取一下。读取主库
exists = orderMapper.selectById(1);
exists = orderMapper.selectOne(
new LambdaQueryWrapper<OrderDO>()
.eq(OrderDO::getUserId, order.getUserId())
);
System.out.println(exists);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class OrderServiceTest {
@Test
public void testAdd() {
OrderDO order = new OrderDO();
order.setUserId(20);
order.setUserId(1);
orderService.add(order);
}

Expand Down