这个是maper配置:
select * from table_many
<select id="findLazyOne" parameterType="java.lang.String" resultType="tableOne" >
select * from table_one t where t.m_id=#{value}
</select>
这个是调用方法:
static TableManyMapper mapper=null;
public static void main(String[] args) throws Exception {
String resource="mybatis.xml";
InputStream input=Resources.getResourceAsStream(resource);
SqlSessionFactory factory=new SqlSessionFactoryBuilder().build(input);
SqlSession sqlSession = factory.openSession();
mapper=sqlSession.getMapper(TableManyMapper.class);
findMany();
sqlSession.commit();
}
public static void findMany(){
List<TableMany> list= mapper.findMany();
for (TableMany tableMany : list) {
System.out.println(tableMany.getM_id()+"::"+tableMany.getM_name());
System.out.println(".......");
List<TableOne> oneList=tableMany.getOneList();
for (TableOne tableOne : oneList) {
System.out.println(tableOne.getO_id()+"::"+tableOne.getO_name());
}
}
}
这个是报错:
32acceba-7d07-11e7-acb7-14dda920ec0e::多的一方1
.......
Exception in thread "main" org.apache.ibatis.executor.ExecutorException: Statement returned more than one row, where no more than one was expected.
at org.apache.ibatis.executor.ResultExtractor.extractObjectFromList(ResultExtractor.java:50)
at org.apache.ibatis.executor.loader.ResultLoader.loadResult(ResultLoader.java:71)
at org.apache.ibatis.executor.loader.ResultLoaderMap$LoadPair.load(ResultLoaderMap.java:207)
at org.apache.ibatis.executor.loader.ResultLoaderMap$LoadPair.load(ResultLoaderMap.java:172)
at org.apache.ibatis.executor.loader.ResultLoaderMap.load(ResultLoaderMap.java:80)
at org.apache.ibatis.executor.loader.cglib.CglibProxyFactory$EnhancedResultObjectProxyImpl.intercept(CglibProxyFactory.java:147)
at com.mybatis.pojo.TableMany$$EnhancerByCGLIB$$49d2b6d7.getOneList()
at com.mybatis.test.ManayToOne.findMany(ManayToOne.java:62)
at com.mybatis.test.ManayToOne.main(ManayToOne.java:28)