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);
    }

}

 

posted @ 2020-12-22 14:44  TIMEAWAY  阅读(850)  评论(0编辑  收藏  举报