例如:给定一个分类表和子分类表

得到如下信息:

1.一个分类的完整信息;

2.根据分类获取其对应的子分类

package Mapping_transformation;

class item
{
private long id ;
private String title ;
private subitem subitems[] ; //一个分类有多个子分类
public item(long id , String title)
{
this.id = id ;
this.title = title ;
} public void setSubitems(subitem[] subitems) {
this.subitems = subitems;
} public subitem[] getSubitems() {
return subitems;
} public String getInfo()
{
return "【分类信息】id = "+this.id + " title = "+this.title ;
} }
class subitem
{
private long id ;
private String title ;
private item item ;
public subitem(long id , String title)
{
this.id = id ;
this.title = title ;
}
public void setItem(item item)
{
this.item = item ;
}
public item getItem()
{
return item ;
}
public String getInfo()
{
return "【子分类信息】id = "+this.id + " title = "+this.title ;
}
}
public class One_to_many {
public static void main(String[] args) {
item item = new item(001,"编程书籍");
subitem subitems[] = new subitem[]{
new subitem(002,"java从入门到放弃"),
new subitem(003,"c++从入门到放弃")
};
item.setSubitems(subitems); //一个分类有多个子分类 for(int i = 0 ; i<subitems.length ; i++)
{
subitems[i].setItem(item);
} System.out.println(item.getInfo());
for(int i = 0 ; i<item.getSubitems().length ; i++)
{
System.out.println(item.getSubitems()[i].getInfo());
}
}
}
resul:
【分类信息】id = 1 title = 编程书籍
【子分类信息】id = 2 title = java从入门到放弃
【子分类信息】id = 3 title = c++从入门到放弃

最新文章

  1. mysql导入大文件sql
  2. EhCache缓存
  3. 难得的中文ASP.NET 5/MVC 6入门教程
  4. 《SQL Server企业级平台管理实践》读书笔记——SQL Server如何设置自动增长和自动收缩项
  5. 在 FREEBUF 投放广告
  6. 使用shape设置只有部分边框有颜色
  7. Spring事务管理中@Transactional
  8. D. Green and Black Tea
  9. Codeforces Round #308 (Div. 2) D. Vanya and Triangles 水题
  10. 向PHP语言进发
  11. python threading 模块来实现多线程
  12. rebase
  13. 【2016年终大典】i春秋一年中不可错过的安全精华
  14. 【Java面试宝典】深入理解JAVA虚拟机
  15. Go 标准库 —— sync.Mutex 互斥锁
  16. Java API概述
  17. logback配置详解
  18. 在Linux下面如何查看tomcat已经使用多少线程(Threads)
  19. int与String互转
  20. php -- 显示当前时间

热门文章

  1. Dockerfile 定制镜像
  2. 建议收藏:.net core 使用导入导出Excel详细案例,精心整理源码已更新至开源模板
  3. javaScipt类定义和实现
  4. spring boot打包成war包的页面该放到哪里?
  5. Java学习总结之基本数据类型
  6. NOIP 模拟29 B 侥幸
  7. javascript中判断数据类型
  8. linux shell脚本语法笔记
  9. windows下载安装swoole的方法
  10. kubernetes 控制器详解【持续完善中】