编写测试方法
public void getAddressListByUserIdTest(){ SqlSession sqlSession=null; try{ sqlSession=MyBatisUtil.createSqlSession(); List<User> userList=sqlSession.getMapper(UserMapper.class).getAddressListByUserId(1); for (User user: userList) { System.out.println(user.getUserName()); List<Address> addresses=user.getAddressList(); for (Address address: addresses) { System.out.println("--- "+address.getContact()); } } }catch (Exception ex){ ex.printStackTrace(); }finally { MyBatisUtil.closeSqlSession(sqlSession); } } resultMap自动映射级别autoMappingBehavior的三个级别
NONE:禁止自动匹配
PARTIAL:(默认)自动匹配所有属性,有内部嵌套(assocition,collection)除外
FULL:自动匹配所有
可能有很多东西讲的不是很清晰,希望大家可以留言讨论
by 安心