示例#1
0
 public User getUserById(Integer userId) {
   SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
   try {
     UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
     return userMapper.getUserById(userId);
   } finally {
     sqlSession.close();
   }
 }
示例#2
0
 public List<User> getAllUsers() {
   SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
   try {
     UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
     return userMapper.getAllUsers();
   } finally {
     sqlSession.close();
   }
 }
示例#3
0
 public void deleteUser(Integer userId) {
   SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
   try {
     UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
     userMapper.deleteUser(userId);
     sqlSession.commit();
   } finally {
     sqlSession.close();
   }
 }
示例#4
0
 public void insertUser(User user) {
   SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
   try {
     UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
     userMapper.insertUser(user);
     sqlSession.commit();
   } finally {
     sqlSession.close();
   }
 }