1.1 一对一查询
5. 配置OrderMapper.xml
select * from orders o,user u where o.uid=u.id
6. 测试结果
OrderMapper mapper = sqlSession.getMapper(OrderMapper.class);List
4. 创建UserMapper接口
public interface UserMapper { List
5. 配置UserMapper.xml
一对多查询
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
List
for(User user : all){
System.out.println(user.getUsername());
List
for(Order order : orderList){ System.out.println(order);
}
System.out.println("----------------------------------");}
4. 添加UserMapper接口方法
List
配置UserMapper.xml
select u.*,r.*,r.id rid from user u left join user_role ur on u.id=ur.user_id inner join role r on ur.role_id=r.id
6. 测试结果
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
List
for(User user : all){
System.out.println(user.getUsername());
List
for(Role role : roleList){
System.out.println(role); }
System.out.println("----------------------------------");
}