实体类
Java代码
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;
}
}
Xml代码
<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>