标签:findall setname get runner oid 总数 user pos null
public interface UserCrudRepository extends CrudRepository<User, Long> {
}
1
2
UserCrudRepositoryTests:
@RunWith(SpringRunner.class)
@SpringBootTest
public class UserCrudRepositoryTests {
@Autowired
private UserCrudRepository userCrudRepository;
/**
* 新增
*/
@Test
public void add() {
User user = new User();
user.setName("ljk2");
user.setSex("1");
user.setAge(18);
user.setAddress("beijing");
User result = userCrudRepository.save(user);
Assert.assertNotNull(result);
}
/**
* 修改
*/
@Test
public void edit() {
User user = new User();
user.setId(1l);
user.setName("ljk2edit");
user.setSex("1");
user.setAge(18);
user.setAddress("beijing");
User result = userCrudRepository.save(user);
Assert.assertNotNull(result);
}
/**
* 根据id查询
*/
@Test
public void findById() {
Optional<User> userOptional = userCrudRepository.findById(1L);
User result = userOptional.get();
System.out.println(result);
}
/**
* 查询所有
*/
@Test
public void findAll() {
List<User> userList = (List<User>) userCrudRepository.findAll();
System.out.println(userList);
}
/**
* 计算总数
*/
@Test
public void count() {
long count = userCrudRepository.count();
System.out.println(count);
}
}
标签:findall setname get runner oid 总数 user pos null
原文地址:https://www.cnblogs.com/hyhy904/p/11369951.html