08-根据id删除用户

/*
    删除客户案例
     */
    @Test
    public void testRemove(){
        //1、通过工具类获取entityManager
        EntityManager entityManager = JpaUtils.getEntityManager();
        //2、开启事务
        EntityTransaction tx = entityManager.getTransaction();
        tx.begin();
        //3、增删改查---删除客户
        //(1)先根据id查询客户
        Customer customer = entityManager.find(Customer.class, 1l);
        //(2)调用remove方法进行删除
        entityManager.remove(customer);
        //4、提交事务
        tx.commit();
        //5、释放资源
        entityManager.close();
    }
posted @ 2021-10-30 18:46  不是孩子了  阅读(108)  评论(0)    收藏  举报