你好,
做项目的时候,会遇到很多这样的问题:
有两个实体类A和B:
实体类A怎么写,
最后可以能达到这样的效果:
实体A(1) 有4个实体B(1),2个实体B(2),5个实体B(3)...
实体A(2) 有3个实体B(1),1个实体B(2),7个实体B(3)...
....
很逗比的问题
public class A
{
/**
* 存放b1
/
public B[] bs1;
/*
* 存放b2
/
public B[] bs2;
/*
* 存放b3
*/
public B[] bs3;
/**
* 创建a 实例
* <默认构造函数>
*/
public A(int a, int b, int c)
{
bs1 = createB("B1",a);
bs2 = createB("B2",b);
bs3 = createB("B3",c);
}
B[] createB(String type, int n)
{
B[] bs = new B[n];
for (int i = 0; i < n; i++)
{
bs[i]=new B(type);
}
return bs;
}
public static void main(String[] args)
{
new A(4, 2, 5);
new A(3, 1, 7);
}
}
class B
{
public String b;
public B(String b)
{
this.b = b;
}
}
class A
{
public ArrayList BList; //想要几个就几个。别的类似
}
大家好,我表达的不是太好,这是目前代码的类似结构:
@Entity
class B
{
private String b;
public B(String b)
{
this.b = b;
}
/* B`s Setter & Getter ... */
}
@Entity
class C
{
private B b;
private Int i;
public C(B b,Int i)
{
this.b = b;
this.i=i;
}
/* b ,i`s Setter & Getter ... */
}
@Entity
public class A
{
private List<C> bList;
/* bList`s Setter & Getter ... */
}
请大家帮忙简化一下。