Search in sources :

Example 1 with LambdaUpdateChainWrapper

use of com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper in project demo-SpringBoot by Max-Qiu.

the class TestWrappers method testWrapper.

@Test
void testWrapper() {
    // 创建一个空条件的查询构造器(其实用不到,条件为空的话可以直接传null,比如 userMapper.selectList(null))
    QueryWrapper<User> emptyWrapper = Wrappers.emptyWrapper();
    // 创建一个查询构造器(推荐用Lambda,毕竟queryWrapper.eq("username", "max")这种写String的方式看起来不咋地)
    QueryWrapper<User> queryWrapper1 = Wrappers.query();
    QueryWrapper<User> queryWrapper2 = Wrappers.query(new User());
    // 创建一个支持Lambda语法查询构造器(推荐,详细区别见下方代码)
    LambdaQueryWrapper<User> lambdaQueryWrapper1 = Wrappers.lambdaQuery();
    // 如果不使用对象接收直接链式...写法,可以使用下面这种写法设置泛型
    Wrappers.<User>lambdaQuery();
    LambdaQueryWrapper<User> lambdaQueryWrapper3 = Wrappers.lambdaQuery(User.class);
    LambdaQueryWrapper<User> lambdaQueryWrapper4 = Wrappers.lambdaQuery(new User());
    // 创建一个支持Lambda语法且支持链式写法的查询构造器
    LambdaQueryChainWrapper<User> lambdaQueryChainWrapper = new LambdaQueryChainWrapper<>(userMapper);
    UpdateWrapper<User> updateWrapper1 = Wrappers.update();
    UpdateWrapper<User> updateWrapper2 = Wrappers.update(new User());
    LambdaUpdateWrapper<User> lambdaUpdateWrapper1 = Wrappers.lambdaUpdate();
    LambdaUpdateWrapper<User> lambdaUpdateWrapper2 = Wrappers.lambdaUpdate(new User());
    LambdaUpdateWrapper<User> lambdaUpdateWrapper3 = Wrappers.lambdaUpdate(User.class);
    LambdaUpdateChainWrapper<User> lambdaUpdateChainWrapper = new LambdaUpdateChainWrapper<>(userMapper);
}
Also used : User(com.maxqiu.demo.entity.User) LambdaUpdateChainWrapper(com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper) LambdaQueryChainWrapper(com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

LambdaQueryChainWrapper (com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper)1 LambdaUpdateChainWrapper (com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper)1 User (com.maxqiu.demo.entity.User)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1