SSH添加用户

    public void TianJia(Usertest u) {
           Session s= null;
           Transaction ts = null;
            try {
                s=sessionFactory.openSession();
                ts=s.beginTransaction();//开始事务
                s.save(u);
                ts.commit();    //提交事务

            } catch (Exception e) {
                e.printStackTrace();
                ts.rollback();     //出现异常,回滚事务

            }finally{
                if(s!=null&&s.isOpen()){
                    s.close();
                }
            }
        
    }
原文地址:https://www.cnblogs.com/laohan110/p/3538290.html