一段简单的代码 却是我要努力去接受的
来源:互联网 发布:正义的伙伴 知乎 编辑:程序博客网 时间:2024/04/29 11:08
今天老师教了个知识点,还是有点晕了,三层架构都没搞怎么懂,不知道该如何是好,下面这是老师给我们的关于集合深入运用的代码,真不明白JAVA怎么比WINFORM这么难...希望自己选择的是对的把...
//数据库的数据
use master
go
if exists(select * from sysdatabases where name='business')
drop database business
go
create database business
go
use business
go
create table productType
(
tid int identity(1,1) primary key,
tname varchar(30) not null,
tpid int not null,
remark varchar(50)
)
go
select * from producttype
go
--插入父类型数据
insert into producttype
values('裙子',0,'女人的曲线美')
insert into producttype
values('帽子',0,'装饰你的气质')
--插入各父类型的子类型数据
insert into producttype
values('牛仔裙',1,'野蛮个性')
insert into producttype
values('连衣裙',1,'诱惑指数极高')
insert into producttype
values('超短裙',1,'低头率不胜数计')
insert into producttype
values('鸭舌帽',5,'可爱型')
insert into producttype
values('草帽',5,'简单而不平凡')
insert into producttype
values('爵士帽',5,'成熟男人的选择')
insert into producttype
values('睡裙',1,'老公的最爱')
select * from producttype
go
--hash<parent,childs>
--
--hash<ProductType,ArrayList<ProductType>>
create table productinfo
(
pid int identity(1,1) primary key,
pname varchar(30) not null,
ptype int references productType(tid),
price money,
pdesc varchar(100)
)
go
select * from productinfo
go
insert into productinfo
values('真维斯连衣裙',3,128.0,'高贵大方得体')
insert into productinfo
values('李宁运动帽',6,52.0,'运动无极限')
select * from producttype
select * from productinfo
go
--父类型的集合 ArrayList
select * from producttype where tpid=0
--子类型的集合 ArrayList
select * from producttype where tpid<>0
//JAVA代码
package test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import com.xiaogang.dao.Dao;
import com.xiaogang.pojo.POJO;
import com.xiaogang.pojo.ProductType;
import com.xiaogang.type.dao.ProductTypeDao;
public class FixCollection {
public static void main(String[] args) {
Dao dao = new ProductTypeDao();
List<POJO> parent = dao.query("select * from producttype where tpid=0");
System.out.println(parent);
List<POJO> childs = dao.query("select * from producttype where tpid<>0");
System.out.println(childs);
HashMap hm = new HashMap();
Iterator itr = parent.iterator();
while(itr.hasNext()){
ProductType ptype = (ProductType)itr.next();
ArrayList al = new ArrayList();
Iterator ite = childs.iterator();
while(ite.hasNext()){
ProductType ctype = (ProductType)ite.next();
if(ctype.getTypeParentId()==ptype.getTypeId()){
al.add(ctype);
}
}
hm.put(ptype, al);
}
//HashMap
Iterator ita = hm.keySet().iterator();
while(ita.hasNext()){
ProductType key = (ProductType)ita.next();
System.out.println(key.getTypeName());
ArrayList al = (ArrayList)hm.get(key);
Iterator itt = al.iterator();
while(itt.hasNext()){
ProductType value = (ProductType)itt.next();
System.out.println(" "+value.getTypeName());
}
}
}
}
- 一段简单的代码 却是我要努力去接受的
- 很努力,却始终没有别人混的好---我觉得是“认真”的问题
- 一段简单的代码
- 一段非常值得珍藏的Java代码,Socket模拟容器,尽管简单但却很有意义
- 一段简单的事件代码
- 一段简单的Delphi代码
- 一段简单的javascript代码
- 一段看似简单却不简单、老生常谈的程序
- 我会像对待女朋友那样去呵护我的代码,却不会像写代码那样去对待我的女朋友。。。
- 我会努力去追寻自己的梦想的
- 我在复习呢 一直在 比较努力 我用的是正德的 号码 正德在旁边 我去学习 让正德帮我看着
- 让我弃linux从windows2003的原因:一个简单却是极其致命的安全问题
- 我的一段感情经历(对过去的回忆)
- 这是我第一篇文章 我会努力做好的
- 我最耻辱的一段代码
- ajax 我写的一段代码
- 一段改变我思想的代码!!!
- 换IP的是你,凭啥重启的却是我
- 10个你可能不知道的CSS技巧
- 电信fangying
- 2010年4月6日!值得纪念的一天,100000!!!
- Java可视化象棋!
- 几个问题(十三)------tomcat,Jboss,weblogic区别,容器的作用
- 一段简单的代码 却是我要努力去接受的
- 基础之C语言
- spring学习笔记
- 做一棵永远成长的苹果树
- 复习考研中……
- Sockets编程--网络传输对象(聊天室)
- 笔记一则
- 告诉自己 加油
- “人都是在不断地反抗自己周围的环境中成长起来的 ”