一、SqlMapConfig.xml中开启延迟加载
二、mapper.xml中配置如下
三、pom.xml加入cglib依赖
cglib cglib 2.2.2
四、测试用例
@Test public void testFindOrdersUserLazyLoading() throws Exception{ SqlSession sqlSession = factory.openSession(); OrdersCustomMapper ordersCustomMapper = sqlSession.getMapper(OrdersCustomMapper.class); Listlist = ordersCustomMapper.findOrdersUserLazyLoading(); for(Orders orders : list) { User u = orders.getUser(); System.out.println(u); } }