//1.sqlsession的获取:
//类:GetSqlSession, 返回sqlsession对象,无参
public class GetSqlSession { public static SqlSession createSqlSession() { SqlSessionFactory sqlSessionFactory = null; InputStream input = null; SqlSession session = null; try { //获取mybatis的配置环境。 String resource = "mybatis-config.xml("1.这里写配置文件名")"; //以流的方式获取resource(流的环境配置文件) input = Resources.getResourceAsStream(resource); //创建工厂会话。 sqlSessionFactory = new SqlSessionFactoryBuilder().build(input); // 通过工厂得到SqlSession session = sqlSessionFactory.openSession(); return session; } catch (IOException e) { e.printStackTrace(); return null; } } }