摘要:本文主要向大家介绍了数据库的mybatis自关联关系,通过具体的内容向大家展现,希望大家在学习数据库的路上走的更远。
本文主要向大家介绍了数据库的mybatis自关联关系,通过具体的内容向大家展现,希望大家在学习数据库的路上走的更远。
mybatis自关联关系映射
新闻栏目如下数据库结构:

实体对象
package com.iotek.po;
import java.util.Set;
public class NewsLabel {
private Integer id;
private String name;
private Setchildren;
public NewsLabel() {
// TODO Auto-generated constructor stub
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public SetgetChildren() {
return children;
}
public void setChildren(Setchildren) {
this.children = children;
}
@Override
public String toString() {
return "NewsLabel [id=" + id + ", name=" + name + ", children="
+ children + "]";
}
}
mapper接口:
package com.iotek.dao;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Param;
import com.iotek.po.NewsLabel;
public interface NewsLabelDao {
ListgetChildrenByPid(int pid);
}
mapper映射:
测试方法:
@Test
public void getStudentById() throws IOException {
SqlSession sqlSession = Utils.getSqlSessionFactory().openSession();
NewsLabelDao newsDao=sqlSession.getMapper(NewsLabelDao.class);
List
children=newsDao.getChildrenByPid(2);
for(NewsLabel news:children){
System.out.println(news);
}
}测试结果:
NewsLabel [id=3, name=NBA, children=[NewsLabel [id=6, name=湖人, children=[]], NewsLabel [id=5, name=火箭, children=[]]]]
NewsLabel [id=4, name=CBA, children=[]]
希望这篇文章可以帮助到你,总之同学们,IT资讯尽在职坐标。
喜欢 | 0
不喜欢 | 0
您输入的评论内容中包含违禁敏感词
我知道了

请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号