然后是student_mapper.xml,主要是具体的sql语句:
select student_id, student_name from student; insert into student(student_id, student_name) values(#{studentId, jdbcType=INTEGER}, #{studentName, jdbcType=VARCHAR}); 建立一个MyBatisUtil.java,用于建立一些MyBatis基本元素的,后面的类都继承这个类:public class MyBatisUtil{ protected static SqlSessionFactory ssf; protected static Reader reader; static { try { reader = Resources.getResourceAsReader("config.xml"); ssf = new SqlSessionFactoryBuilder().build(reader); } catch (IOException e) { e.printStackTrace(); } } protected SqlSession getSqlSession() { return ssf.openSession(); }}企业级开发讲求:1、定义和实现分开2、分层开发,通常情况下为Dao–>Service–>Controller,不排除根据具体情况多一层/几层或少一层所以,先写一个StudentDao.java接口:public interface StudentDao{ public List selectAllStudents(); public int insertStudent(Student student);}最后写一个StudentDaoImpl.java实现这个接口,注意要继承MyBatisUtil.java类:public class StudentDaoImpl extends MyBatisUtil implements StudentDao{ private static final String NAMESPACE = "StudentMapper."; public List selectAllStudents()