Search in sources :

Example 16 with User

use of com.maxqiu.demo.entity.User in project demo-SpringBoot by Max-Qiu.

the class TestUser method updateById.

@Test
void updateById() {
    // UPDATE smp_user SET username=? WHERE id=?
    User user = new User();
    user.setId(123L);
    user.setUsername("11111111111");
    boolean b = user.updateById();
    System.out.println(b);
}
Also used : User(com.maxqiu.demo.entity.User) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with User

use of com.maxqiu.demo.entity.User in project demo-SpringBoot by Max-Qiu.

the class TestUser method selectOne.

@Test
void selectOne() {
    // SELECT id,username,age,email FROM smp_user WHERE (age > ? AND age < ?)
    LambdaQueryWrapper<User> queryWrapper = Wrappers.lambdaQuery();
    queryWrapper.gt(User::getAge, 50).lt(User::getAge, 100);
    // 慎用!!!除非保证查询后的结果只有一条或者为空,否则会抛出异常 Expected one result (or null) to be returned by selectOne(), but found: 5
    User user = new User().selectOne(queryWrapper);
    System.out.println(user);
}
Also used : User(com.maxqiu.demo.entity.User) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with User

use of com.maxqiu.demo.entity.User in project demo-SpringBoot by Max-Qiu.

the class StringOperationsTest method get.

/**
 * GET
 */
@Test
@Order(1)
void get() {
    // 获取不存在的键
    assertNull(stringValueOperations.get("nonexistent"));
    // 获取String类型的数据
    stringValueOperations.set("key", "hello");
    assertEquals("hello", stringValueOperations.get("key"));
    // 获取对象类型的数据
    User user = new User(1, "tom", new BigDecimal(18));
    userValueOperations.set("user", user);
    assertEquals(user, userValueOperations.get("user"));
    integerValueOperations.set("num", 1);
    assertEquals(1, integerValueOperations.get("num"));
    redisTemplate.delete(Arrays.asList("user", "key", "num"));
}
Also used : User(com.maxqiu.demo.entity.User) BigDecimal(java.math.BigDecimal) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 19 with User

use of com.maxqiu.demo.entity.User in project demo-SpringBoot by Max-Qiu.

the class SetOperationsTest method type.

/**
 * 测试不同类型
 */
@Test
@Order(2)
void type() {
    // 对象类型
    Long add = userSetOperations.add("users", new User(1, "tom", new BigDecimal(185)), new User(2, "tom", new BigDecimal(183)));
    Long size = userSetOperations.size("users");
    assertEquals(add, size);
    // 数字类型
    Long nums = integerSetOperations.add("nums", 1, 2, 3, 3);
    assertEquals(3, nums);
    // 删除数据
    redisTemplate.delete(Arrays.asList("users", "nums"));
}
Also used : User(com.maxqiu.demo.entity.User) BigDecimal(java.math.BigDecimal) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 20 with User

use of com.maxqiu.demo.entity.User in project demo-SpringBoot by Max-Qiu.

the class UserMapper2Test method addUser.

@Test
void addUser() {
    for (int i = 0; i < 10; i++) {
        User user = new User();
        user.setUsername("TOM" + i);
        user.setGroupId(i % 2);
        user.setEmail(i + "xxx@xxx.com");
        userMapper.insert(user);
    }
}
Also used : User(com.maxqiu.demo.entity.User) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

User (com.maxqiu.demo.entity.User)61 Test (org.junit.jupiter.api.Test)55 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)55 ArrayList (java.util.ArrayList)9 LambdaUpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper)5 BigDecimal (java.math.BigDecimal)3 Order (org.junit.jupiter.api.Order)3 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)2 LambdaQueryChainWrapper (com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper)2 SearchHit (org.springframework.data.elasticsearch.core.SearchHit)2 NativeSearchQuery (org.springframework.data.elasticsearch.core.query.NativeSearchQuery)2 NativeSearchQueryBuilder (org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder)2 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 LambdaUpdateChainWrapper (com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 MyPage (com.maxqiu.demo.model.MyPage)1 ParamSome (com.maxqiu.demo.model.ParamSome)1 List (java.util.List)1 RowBounds (org.apache.ibatis.session.RowBounds)1