zoukankan      html  css  js  c++  java
  • MyBatis-Plus的条件构造器 EntryWrapper和Condition

    public class TestMP {
        private ApplicationContext ioc = new ClassPathXmlApplicationContext("applicationContext.xml");
    
        private UserMapper userMapper = ioc.getBean("userMapper", UserMapper.class);/**
         * 条件构造器查询  查询
         */
        @Test
            public void entityWrapperSelect() {
            EntityWrapper<User> wrapper = new EntityWrapper<User>();
            wrapper.between("age",20,28);
            wrapper.eq("name","lc");
            wrapper.like("email","12");
            List<User> users = userMapper.selectList(wrapper);
            System.out.println(users);
        }
    
        /**
         * 条件构造器查询  修改
         */
        @Test
        public void entityWrapperUpdate() {
            User user = new User();
            user.setName("Jack");
            EntityWrapper<User> wrapper = new EntityWrapper<User>();
            wrapper.between("age",20,22);
            wrapper.eq("name","lc");
            wrapper.like("email","12");
            Integer update = userMapper.update(user, wrapper);
            System.out.println(update);
        }
    
        /**
         * 条件构造器查询  删除
         */
        @Test
        public void entityWrapperDelete() {
            EntityWrapper<User> wrapper = new EntityWrapper<User>();
            wrapper.between("age",20,26);
            wrapper.eq("name","lc");
            wrapper.like("email","12");
            Integer update = userMapper.delete(wrapper);
            System.out.println(update);
        }
    
        /**
         * 条件构造器查询  查询排序
         */
        @Test
        public void entityWrapperOrder() {
            EntityWrapper<User> wrapper = new EntityWrapper<User>();
            wrapper.eq("age",28);
            wrapper.orderBy("id",false);
            List<User> users = userMapper.selectList(wrapper);
            System.out.println(users);
        }
    
        /**
         * 条件构造器查询  condition查询
         */
        @Test
        public void entityConditionSelect() {
            Condition condition = Condition.create();
            condition.between("age",20,28);
            condition.eq("name","lc");
            condition.like("email","12");
            List<User> users = userMapper.selectList(condition);
            System.out.println(users);
        }
    
    }
  • 相关阅读:
    分支可以类型的多态实现
    c#中使用了using自动释放资源,如果在using中被return或者异常终止,也会继续执行dispose函数的
    C# 数组的Clone
    pg_dump备份数据结构及数据
    SpringBoot使用MockMVC单元测试Controller
    Docker连接私服
    Windows安装Docker
    项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde
    剑指Offer对答如流系列
    剑指Offer对答如流系列
  • 原文地址:https://www.cnblogs.com/lc0605/p/14172987.html
Copyright © 2011-2022 走看看