MyBatis系列(二) MyBatis接口绑定与多参数传递
前言 通过上一篇博文的,已经可以做到通过MyBatis连接数据库,现在再来介绍一种方法通过接口绑定SQL语句。 不使用接口绑定的方式 不使用接口绑定的方式,是通过调用SqlSession中的selectxxx方法,通过传递一个String类型的参数(通常为namespace的属性+SQLID),来寻找对应SQL文件中的参数。 测试类: //创建SqlSessionFactory对象,并指向全局配置文件mybatis-config.xml public SqlSessionFactory getSqlSessionFactory() throws IOException { String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); return new SqlSessionFactoryBuilder().build(inputStream); } @Test public void test() throws IOException { //引用SqlSessionFactory对象 SqlSessionFactory sqlSessionFactory = getSqlSessionFactory(); /