public void selectByIdNamespaceWay(int id) { SqlSession session = sqlSessionFactory.openSession(); try { User user = (User) session.selectOne("com.frames.mybatis.inter.UserMapper.selectUserByID", id); System.out.println(user.getUserAddress()); System.out.println(user.getUserName()); } finally { session.close(); } }
public void selectByIdInterfaceWay(int id) { SqlSession session = sqlSessionFactory.openSession(); try { IUserOperation userOperation = session.getMapper(IUserOperation.class); User user = userOperation.selectUserByID(id); System.out.println(user.getUserAddress()); System.out.println(user.getUserName()); } finally { session.close(); } }
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(); } }