findOne(id) : 根据Id查询

    1. @Test
    2. public void testFindOne(){
    3. Customer customer = customerDao.findOne(3l);
    4. System.out.println(customer);
    5. }
    1. /**
    2. * 测试统计查询:查询客户的总数量
    3. * count:统计总条数
    4. */
    5. @Test
    6. public void testCount(){
    7. long count = customerDao.count();//查询全部的客户数量
    8. System.out.println(count);
    9. }
    1. /**
    2. * 测试:判断id为4的客户是否存在
    3. * 1.可以查询一下id为4的客户
    4. * 如果值为空,代表不存在在,如果不为空,代表存在
    5. * 2.判断数据库中id为4的客户的数量
    6. * 如果数量为0,代表不存在,如果大于0,代表存在
    7. */
    8. @Test
    9. public void testExists(){
    10. boolean exists = customerDao.exists(4l);
    11. System.out.println("id为4的客户是否存在:" + exists);
    12. }
    1. /**
    2. * 根据id从数据库中查询
    3. * @Transactional : 保证getOne正常运行
    4. *
    5. * findOne:
    6. * em.find() :立即加载
    7. * getOne:
    8. * em.getReference :延迟加载
    9. * * 返回的是一个客户的动态代理对象
    10. * * 什么时候用,什么时候查询
    11. */
    12. @Test
    13. @Transactional
    14. public void testGetOne(){
    15. Customer customer = customerDao.getOne(4l);
    16. System.out.println(customer);
    17. }