Mybatis_modify and delete

Revise.

    <update id="update" parameterType = "xxx.x.Person">
        update person t set
        t.name = #{name},
        t.gender = #{gender},
        t.person_addr = #{personAddr},
        t.birthday = #{birthday}
        where t.person_id = #{personId}
    </update>
public void update() {
        //创建SqlSession
        SqlSession session = sessionFactory.openSession();
        try {
            Person p = new Person();
            p.setId(2);
            p.setName( "Li Si" );
            p.setGender(1);
            p.setAddress( "Shanghai" );
            p.setBirthday( new Date());
             int count = session.update("xxx.x.mapper.PersonTestMapper.update",p); // There is a return value here, which is the number of rows affected 
            session.commit( ); // Database changes (additions, deletions and changes) must be submitted to the transaction 
            System.out.println(count);
        }catch (Exception e) {
            e.printStackTrace ();
            session.rollback();
        }finally {
            session.close();
        }
        
    }

 delete:

    <delete id = "delete" parameterType = "java.lang.Integer">
        delete from person where person_id = #{id}
    </delete>
    public void delete() {
        //创建SqlSession
        SqlSession session = sessionFactory.openSession();
        try {
            
            int count = session.delete("xxx.x.mapper.PersonTestMapper.delete",3); // Delete the row with id 3 
            session.commit(); // Database changes (additions, deletions and changes) must submit transactions 
            System.out.println(count);
        }catch (Exception e) {
            e.printStackTrace ();
            session.rollback();
        }finally {
            session.close();
        }
        
    }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325479807&siteId=291194637