提交 466edc38 authored 作者: 陈世营's avatar 陈世营

分页查询测试

上级 8f0be3f3
package com.loit.shardingsphere.seata.controller; package com.loit.shardingsphere.seata.controller;
import com.loit.shardingsphere.seata.modules.entity.OrderEntity;
import com.loit.shardingsphere.seata.modules.service.IBusinessService; import com.loit.shardingsphere.seata.modules.service.IBusinessService;
import com.loit.shardingsphere.seata.modules.service.IOrderService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/** /**
* 前端控制器 * 前端控制器
*/ */
...@@ -19,14 +23,23 @@ public class DemoController { ...@@ -19,14 +23,23 @@ public class DemoController {
@Autowired @Autowired
IBusinessService businessService; IBusinessService businessService;
@Autowired
IOrderService orderService;
@GetMapping("purchase") @GetMapping("purchase")
public void purchase() { public void purchase() {
for (long i = 10; i < 20; i++) { for (long i = 1; i < 20; i++) {
businessService.purchase(i); businessService.purchase(i);
} }
log.info("success"); log.info("success");
} }
@GetMapping("findPage")
public void findPage() {
List<OrderEntity> pageList = orderService.findPage(0l, 5l);
log.info(pageList.toString());
}
} }
...@@ -3,7 +3,18 @@ package com.loit.shardingsphere.seata.modules.service; ...@@ -3,7 +3,18 @@ package com.loit.shardingsphere.seata.modules.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.loit.shardingsphere.seata.modules.entity.OrderEntity; import com.loit.shardingsphere.seata.modules.entity.OrderEntity;
import java.util.List;
public interface IOrderService extends IService<OrderEntity> { public interface IOrderService extends IService<OrderEntity> {
void insertOrder(OrderEntity orderEntity); void insertOrder(OrderEntity orderEntity);
/**
* 分页查询库存信息
*
* @PageNum 当前页
* @PageSize 每页显示数量
*/
List<OrderEntity> findPage(Long pageNum, Long pageSize);
} }
...@@ -31,4 +31,5 @@ public class BusinessServiceImpl implements IBusinessService { ...@@ -31,4 +31,5 @@ public class BusinessServiceImpl implements IBusinessService {
orderService.insertOrder(orderEntity); orderService.insertOrder(orderEntity);
//throw new RuntimeException("回滚测试"); //throw new RuntimeException("回滚测试");
} }
} }
package com.loit.shardingsphere.seata.modules.service.impl; package com.loit.shardingsphere.seata.modules.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.loit.shardingsphere.seata.modules.entity.OrderEntity; import com.loit.shardingsphere.seata.modules.entity.OrderEntity;
import com.loit.shardingsphere.seata.modules.mapper.OrderMapper; import com.loit.shardingsphere.seata.modules.mapper.OrderMapper;
import com.loit.shardingsphere.seata.modules.service.IOrderService; import com.loit.shardingsphere.seata.modules.service.IOrderService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
@Service @Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderEntity> implements IOrderService { public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderEntity> implements IOrderService {
...@@ -13,4 +18,16 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderEntity> impl ...@@ -13,4 +18,16 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderEntity> impl
public void insertOrder(OrderEntity orderEntity) { public void insertOrder(OrderEntity orderEntity) {
baseMapper.insert(orderEntity); baseMapper.insert(orderEntity);
} }
@Override
public List<OrderEntity> findPage(Long pageNum, Long pageSize) {
QueryWrapper<OrderEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.orderByAsc("id");
Page<OrderEntity> page = new Page<>(pageNum, pageSize);
//分页数据
IPage<OrderEntity> pageInfo = this.page(page, queryWrapper);
return pageInfo.getRecords();
}
} }
...@@ -20,14 +20,17 @@ public class LoitShardingsphereSeataApplicationTests { ...@@ -20,14 +20,17 @@ public class LoitShardingsphereSeataApplicationTests {
public void contextLoads() { public void contextLoads() {
try { try {
for (long i = 10; i < 20; i++) {
businessService.purchase(222L);
/* for (long i = 10; i < 20; i++) {
businessService.purchase(i); businessService.purchase(i);
} }*/
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error(e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
} }
log.info("success"); log.info("success");
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论