Search in sources :

Example 1 with User

use of com.goku.demo.model.User in project springBoot-learn-demo by nbfujx.

the class UserRepositoryTest method test.

@Test
public void test() throws Exception {
    // 创建三个User,并验证User总数
    userRepository.save(new User(1L, "didi", 30));
    userRepository.save(new User(2L, "mama", 40));
    userRepository.save(new User(3L, "kaka", 50));
    this.logger.info(String.valueOf(userRepository.findAll().size()));
    // 删除一个User,再验证User总数
    User u = userRepository.findOne(1L);
    this.logger.info(u.toString());
    userRepository.delete(u);
    this.logger.info(String.valueOf(userRepository.findAll().size()));
    // 删除一个User,再验证User总数
    u = userRepository.findByUsername("mama");
    this.logger.info(u.toString());
    userRepository.delete(u);
    this.logger.info(String.valueOf(userRepository.findAll().size()));
}
Also used : User(com.goku.demo.model.User) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 2 with User

use of com.goku.demo.model.User in project springBoot-learn-demo by nbfujx.

the class UserRepositoryTest method test2.

@Test
public void test2() throws Exception {
    // 创建三个User,并验证User总数
    userRepository2.save(new User(1L, "didi22", 30));
    userRepository2.save(new User(2L, "mama22", 40));
    userRepository2.save(new User(3L, "kaka22", 50));
    this.logger.info(String.valueOf(userRepository2.findAll().size()));
    // 删除一个User,再验证User总数
    User u = userRepository2.findOne(1L);
    this.logger.info(u.toString());
    userRepository2.delete(u);
    this.logger.info(String.valueOf(userRepository2.findAll().size()));
    // 删除一个User,再验证User总数
    u = userRepository2.findByUsername("mama22");
    this.logger.info(u.toString());
    userRepository2.delete(u);
    this.logger.info(String.valueOf(userRepository2.findAll().size()));
}
Also used : User(com.goku.demo.model.User) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 3 with User

use of com.goku.demo.model.User in project springBoot-learn-demo by nbfujx.

the class UserRepositoryTest method test3.

@Test
public void test3() throws Exception {
    Pageable pageable = new PageRequest(0, 10);
    Page<User> u1 = userRepository.findByNameAndAgeRange("kaka", 50, pageable);
    this.logger.info(u1.toString());
    Page<User> u2 = userRepository.findByNameAndAgeRange2("kaka", 0, 50, pageable);
    this.logger.info(u2.toString());
    Page<User> u3 = userRepository.findByNameAndAgeRange3("kaka", 0, 50, pageable);
    this.logger.info(u3.toString());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) User(com.goku.demo.model.User) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

User (com.goku.demo.model.User)3 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 PageRequest (org.springframework.data.domain.PageRequest)1 Pageable (org.springframework.data.domain.Pageable)1