人一能之,己百之;人十能之,己千之。——《中庸》
今天踩到一个坑,使用springboot
单元测试时插入数据回滚了
最后发现原来需要在测试类上面加上@Rollback(false)
就可以了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| package com.ruben;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruben.dao.MpUserMapper; import com.ruben.pojo.dataObject.UserDataObject; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.Rollback; import org.springframework.util.SimpleIdGenerator;
import javax.annotation.Resource; import java.util.List; import java.util.UUID; import java.util.stream.Collectors;
@SpringBootTest @Rollback(false) public class MybatisPlusDemo {
@Resource private MpUserMapper mpUserMapper;
@Test public void insert() { mpUserMapper.insert(UserDataObject.builder().id(new SimpleIdGenerator().generateId().variant()).username("Jack").password(UUID.randomUUID().toString()).build()); }
@Test public void test() { IPage<UserDataObject> page = mpUserMapper.selectPage(new Page<>(1, 2), Wrappers.lambdaQuery(UserDataObject.builder().build())); System.out.println(page); LambdaQueryWrapper<UserDataObject> wrapper = Wrappers.lambdaQuery(UserDataObject.builder().build()); List<Integer> userIds = page.getRecords().stream().map(UserDataObject::getId).collect(Collectors.toList()); wrapper.in(UserDataObject::getId, userIds) .and(w -> w.like(UserDataObject::getUsername, "achao").or(wr -> wr.like(UserDataObject::getUsername, "Achao"))); page = mpUserMapper.selectPage(new Page<>(1, 2), wrapper); System.out.println(page); }
}
|