修改.
<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("李四"); p.setGender(1); p.setAddress("上海"); p.setBirthday(new Date()); int count = session.update("xxx.x.mapper.PersonTestMapper.update",p); //此处有一个返回值,是影响的行数 session.commit(); //数据库的变更(增删改)都要提交事务 System.out.println(count); }catch (Exception e) { e.printStackTrace(); session.rollback(); }finally { session.close(); } }
删除:
<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); //删id为3 的那行 session.commit(); //数据库的变更(增删改)都要提交事务 System.out.println(count); }catch (Exception e) { e.printStackTrace(); session.rollback(); }finally { session.close(); } }