1
我想從XML配置遷移到Java配置。將映射器添加到Java中的myBatis配置中
sqlSessionFactory.getConfiguration().setEnvironment(new Environment("development", new org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory(), getDataSouroce()));
我設法更換所有<environments>
部分用Java配置(我從XML配置文件中刪除<environments>
),但我無法擺脫的:
<mappers><mapper resource="mailbox/db/map/FileMapper.xml"/> </mappers>
我試着寫:
sqlSessionFactory.getConfiguration()。addMapper(FileMapper.class);
但也有例外:
SqlSession sqlSession = MyBatisConnectionFactory.instance.getSqlSessionFactory().openSession();
FileExample fe = new FileExample();
Criteria f = fe.createCriteria().andIdBetween(0L, 5L);
FileMapper mapper = (FileMapper) sqlSession.getMapper(FileMapper.class);
List<File> allRecords = mapper.selectByExample(fe);
// Mapped Statements collection does not contain value for mailbox.db.dao.FileMapper.selectByExample