五、条件构造器
package com.jx;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jx.mapper.UserMapper;
import com.jx.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class WrapperTest {
@Autowired
private UserMapper userMapper;
@Test
void select(){
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.isNotNull("name")
.isNull("email")
.orderByAsc("id")
.eq("name","jx");
userMapper.selectList(wrapper);
}
@Test
void selectRange(){
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper
.between("age",15,17);
userMapper.selectList(wrapper);
}
@Test
void selectLike(){
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.like("name","j")
.notLike("email","3");
userMapper.selectList(wrapper);
}
@Test
void testInSql(){
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.ge("age",15)
.inSql("id","select id from user where id<3");
userMapper.selectList(wrapper);
}
}