mybatis 自身关联 映射

实体类


public class Module {

private int id;
private String key;
private String name;
private Module parentModule;
private List<Module> childrenModules;
private String url;
private int sort;
private String show;
private String del;

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getKey() {
return key;
}

public void setKey(String key) {
this.key = key;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Module getParentModule() {
return parentModule;
}

public void setParentModule(Module parentModule) {
this.parentModule = parentModule;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public int getSort() {
return sort;
}

public void setSort(int sort) {
this.sort = sort;
}

public String getShow() {
return show;
}

public void setShow(String show) {
this.show = show;
}

public String getDel() {
return del;
}

public void setDel(String del) {
this.del = del;
}

public List<Module> getChildrenModules() {
return childrenModules;
}

public void setChildrenModules(List<Module> childrenModules) {
this.childrenModules = childrenModules;
}
}




<mapper namespace="com.sagaware.caraccess.mapper.ModuleMapper">

<resultMap type="Module" id="moduleResultMap">
<id property="id" column="module_id"/>
<result property="key" column="module_key"/>
<result property="name" column="module_name"/>
<result property="url" column="module_url"/>
<result property="sort" column="module_sort"/>
<result property="show" column="module_show"/>
<result property="del" column="module_del"/>

<!-- 查询父模块 -->
<association property="parentModule" column="module_parent_id" select="getModulesById" />

<!-- 查询子模块 -->
<collection property="childrenModules" column="module_id" select="getChildrenModues" />

</resultMap>

<select id="getModules" parameterType="String" resultMap="moduleResultMap">
select * from tb_module where module_id=2
</select>

<select id="getModulesById" parameterType="int" resultMap="moduleResultMap">
select * from tb_module where module_id = #{module_id}
</select>

<select id="getChildrenModues" parameterType="int" resultMap="moduleResultMap">
select * from tb_module where module_parent_id = #{module_id}
</select>
</mapper>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值