querywrapper条件构造器
2021/9/21 23:09:54
本文主要是介绍querywrapper条件构造器,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
package com.kuang; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.kuang.mapper.UserMapper; import com.kuang.pojo.User; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import static org.assertj.core.api.Assertions.assertThat; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static org.hamcrest.MatcherAssert.assertThat; @SpringBootTest class MybitisPlusApplicationTests { @Autowired private UserMapper userMapper; @Test void contextLoads() { List<User> users = userMapper.selectList(null); users.forEach(System.out::println); } @Test public void testInsert(){ User user = new User(); user.setName("sdfsdf"); user.setAge(3); user.setEmail("313@qq.com"); int insert = userMapper.insert(user); System.out.println(insert); System.out.println(user); } @Test public void test1OptimisticLocker() { User user = userMapper.selectById(5L); user.setName("sdfsd11f"); user.setEmail("sdfsdf@qqq"); userMapper.updateById(user); } @Test public void testSelectById() { User user = userMapper.selectById(1L); System.out.println(user); } @Test public void testSelect2() { String aa = "2021-08-03 01:00:08"; String aa2 = "2021-09-03 01:00:08"; QueryWrapper<User> betweenWrapper = new QueryWrapper<>(); betweenWrapper.between("create_time", aa, aa2); // SFunction<User, ?> age; List<User> list = userMapper.selectList(betweenWrapper); // .lt(User::getCreateTime, "2021-08-30 01:00:08")); list.forEach(System.out::println); // User user1 = new User(); //// user1.setId(2L); // user1.setName("44444"); // userMapper.update(user1,new QueryWrapper<User>() // .lambda().lt(User::getCreateTime, "2021-08-30 01:00:08")); // User user = userMapper.selectById(1L); // System.out.println(user); } @Test public void testUpdate2() { User user1 = new User(); // user1.setId(2L); user1.setName("44444"); userMapper.update(user1,new QueryWrapper<User>() .lambda().lt(User::getCreateTime, "2021-08-30 01:00:08")); // User user = userMapper.selectById(1L); // System.out.println(user); } @Test public void testSelectByBatchId() { List<User> list = userMapper.selectBatchIds(Arrays.asList(1, 2, 3, 4)); System.out.println(list); } @Test public void testUpdate() { User user = new User(); user.setId(7L); user.setName("关注狂人说公众号11"); user.setAge(21); userMapper.updateById(user); List<User> list = userMapper.selectList(null); list.forEach(System.out::println); } void contextLoads2() { // for(int i=0; i<10; i++){ // User user = new User(); // user.setAge(11); // user.setEmail("qq@qq.com"); // user.setName("jame"+i); // userMapper.insert(user); // } // User user = new User(); // user.setId(8L); // user.setId(3L); // user.setAge(222); // user.setEmail("qq@qq.com"); // user.setName("jame"); // userMapper.insert(user); // User user = new User(); // List<User> list = new ArrayList<>(); // list.add(user ); // assertThat(userMapper.deleteById(4L)); // userMapper.delete(new QueryWrapper<User>() // .lambda().eq(User::getName, "jame2") // ); // userMapper.updateById(new User().setId(2L)); // assertThat(mapper.updateById(new User().setId(1L).setEmail("ab@c.c"))).isGreaterThan(0); // mapper.update(user,null); // mapper.update( // new User().setName("mp"), // Wrappers.<User>lambdaUpdate() // .set(User::getAge, 3) // .eq(User::getId, 2) // ); // User user = mapper.selectById(7); // mapper.update(null, Wrappers.<User>lambdaUpdate().set(User::getName, "aaa").eq(User::getId, 8)); // System.out.println(user); // assertThat(mapper.selectById(8).getEmail()).isEqualTo("qq@qq.com"); // mapper.update( // new User().setEmail("miemie2@baomidou.com"), // Wrappers.<User>lambdaUpdate() // .set(User::getAge, null) // .eq(User::getId, 2) // ); // System.out.println(i); // List<User> users = mapper.selectList(null ); // users.forEach(System.out::println); // System.out.println(users); } }
这篇关于querywrapper条件构造器的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-28知识管理革命:文档软件的新玩法了解一下!
- 2024-11-28低代码应用课程:新手入门全攻略
- 2024-11-28哪些办公软件适合团队协作,且能够清晰记录每个阶段的工作进展?
- 2024-11-28全栈低代码开发课程:零基础入门到初级实战
- 2024-11-28拖动排序课程:轻松掌握课程拖动排序功能
- 2024-11-28如何高效管理数字化转型项目
- 2024-11-28SMART法则好用吗?有哪些项目管理工具辅助实现?
- 2024-11-28深度剖析:6 款办公软件如何构建设计团队项目可视化管理新生态?
- 2024-11-28HTTP缓存课程:新手入门指南
- 2024-11-28实战丨证券 HTAP 混合业务场景的难点问题应对