合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
1.UserMapper.java ~~~ //修改,返回影响行数 int update(User u); ~~~ 2.UserMapper.xml ~~~ <!--修改语句--> <update id="update" parameterType="com.nobb.domain.User"> update t_user set name = #{name},password = #{password} where id = #{id} </update> ~~~ 3.Test.java ~~~ //定义配置文件路径 String resource = "mybatis-config.xml";//不能加 根目录 / InputStream inputStream = null; try {//加载配置文件 inputStream = Resources.getResourceAsStream(resource); } catch (IOException e) { e.printStackTrace(); }//根据配置文件创建SessionFactory对象 SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); //获得SqlSession SqlSession session = sqlSessionFactory.openSession(); //获得UserMapper接口的实现类 UserMapper mapper = session.getMapper(UserMapper.class); //调用UserMapper方法,执行xml中定义的SQL语句 User u = new User(); u.setId(22); u.setName("nobb112111"); u.setPassword("112111"); int row = mapper.update(u); //需要显式提交事务 session.commit(); //需要显式提交事务 session.close(); System.out.println(row); ~~~