两张表SystemParam(系统参数表) Suit (主题)
SystemParam 与 Suit 是多对一
Suit 的higerSuit字段是Suit 的父及主题id 是多对一,需要自连接查询,因为重名所以父表sql字段加别名
mapper方法
Systemparam selectJoinSuit(String strparamcode);
Po类
public class Systemparam {
//ManyToOne "主题"
private Suit suitobj;
private String strparamcode;
private String strenable;
private String strparamname;
//suit表主键
private String suit;
private String strparamvalue;
}
public class Suit {
//ManyToOne
private Suit suit;
//主键
private String strsuitcode;
private String strsuitname;
//父级id
private String higersuit;
}
resultMap的写法
resultMap 使用extends 继承上级map
select写法
补充知识:Mybatis中resultMap标签实现多表查询(多个对象)
1 n+1
1 在teacher中添加List student,
public class Teacher {
private int id;
private String name;
private List list;
2 在studentMapper.xml中添加通过tid查询
3 在TeacherMapper.xml中添加查询全部
其中collection是当属性为集合类型时使用的标签
2 多表联合
以上这篇mybatis 多表关联mapper文件写法操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持考高分网。



