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