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);
        }
    
    }
  • 相关阅读:
    DS博客作业01--日期抽象数据类型设计与实现
    C语言-第6次作业
    C语言-第5次作业
    C语言--第4次作业
    DS博客作业08--课程总结
    DS博客作业07--查找
    DS博客作业06--图
    DS博客作业05--树
    DS博客作业03--栈和队列
    DS作业01--日期抽象数据类型设计与实现
  • 原文地址:https://www.cnblogs.com/lc0605/p/14172987.html
Copyright © 2011-2022 走看看