企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~ import com.nobb.domain.Account; import com.nobb.mapper.AccountMapper; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.junit.Test; import java.io.InputStream; import java.util.List; public class MybatisTest { @Test public void fun1() throws Exception{ //构建输入流 InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml"); //创建sqlSessionFactory SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); //打开Session SqlSession sqlSession = sqlSessionFactory.openSession(); //获取mapper AccountMapper accountMapper = sqlSession.getMapper(AccountMapper.class); List<Account> list = accountMapper.findAll(); System.out.println(list); } } ~~~