Esempio n. 1
0
  /** 测试增加,增加后,必须提交事务,否则不会写入到数据库. */
  public void addUser(User user) {

    SqlSession session = sqlSessionFactory.openSession();
    try {
      IUserOperation userOperation = session.getMapper(IUserOperation.class);
      int i = userOperation.addUser(user);
      System.out.println(i);
      session.commit();
      System.out.println("当前增加的用户 id为:" + user.getId());
    } finally {
      session.close();
    }
  }
Esempio n. 2
0
  public void getUserList0(String userName) {
    SqlSession session = sqlSessionFactory.openSession();
    try {
      IUserOperation userOperation = session.getMapper(IUserOperation.class);
      List<User> users = userOperation.selectUsers0(userName);
      for (User user : users) {
        System.out.println(user.getId() + ":" + user.getUserName() + ":" + user.getUserAddress());
      }

    } finally {
      session.close();
    }
  }