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