コード例 #1
0
 public Student findStudentWithAddressById(int id) {
   SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
   try {
     StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
     return studentMapper.selectStudentWithAddress(id);
   } finally {
     sqlSession.close();
   }
 }
コード例 #2
0
 public List<Student> findAllStudents() {
   SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
   try {
     StudentMapper StudentMapper = sqlSession.getMapper(StudentMapper.class);
     return StudentMapper.findAllStudents();
   } finally {
     sqlSession.close();
   }
 }
コード例 #3
0
 public Student findStudentById(Integer id) {
   logger.debug("findStudentById :" + id);
   SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
   try {
     StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
     return studentMapper.findStudentById(id);
   } finally {
     sqlSession.close();
   }
 }
コード例 #4
0
  public Map<String, Object> findStudentMapById(int id) {

    SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
    try {
      StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
      return studentMapper.findStudentMapById(id);
    } finally {
      sqlSession.close();
    }
  }
コード例 #5
0
 public void createStudentWithMap(Map<String, Object> studentDataMap) {
   SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
   try {
     StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
     mapper.insertStudentWithMap(studentDataMap);
     sqlSession.commit();
   } catch (Exception e) {
     sqlSession.rollback();
     e.printStackTrace();
     throw new RuntimeException(e.getCause());
   } finally {
     sqlSession.close();
   }
 }
コード例 #6
0
 public boolean deleteStudent(int id) {
   SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
   try {
     StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
     int count = mapper.deleteStudent(id);
     sqlSession.commit();
     return count > 0;
   } catch (Exception e) {
     sqlSession.rollback();
     e.printStackTrace();
     throw new RuntimeException(e.getCause());
   } finally {
     sqlSession.close();
   }
 }
コード例 #7
0
 public Student updateStudent(Student student) {
   SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
   try {
     StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
     mapper.updateStudent(student);
     sqlSession.commit();
     return student;
   } catch (Exception e) {
     sqlSession.rollback();
     e.printStackTrace();
     throw new RuntimeException(e.getCause());
   } finally {
     sqlSession.close();
   }
 }