ava代码
public class Entity
{
protected TableMapping tlbMapping; // 与数据表的结构映射关系
protected Map<String, Object> attrs; // entity的属性
protected Set<Class<Entity>> hasOne; // 1对1
protected Set<Class<Entity>> hasMany; // 1对多
protected Set<Class<Entity>> belongsTo; // 多对1
protected Set<Class<Entity>> hasAndBelongsToMany; // 多对多
public void setAttr(String attrName, Object value)
{
attrs.put(attrName, value);
}
public Object getAttr(String attrName)
{
return attrs.get(attrName);
}
/**
* 重载这个方法,用来设置关系
*/
public void setRelation()
{
// 在这里手动的设置关系,1对1,1对多。。。
hasOne(...);
belongsTo(...);
...
}
protected void hasOne(Class<Entity>... clazzs)
{
for (Class<Entity> clazz : clazzs)
hasOne.add(clazz);
}
protected void belongsTo(Class<Entity>... clazzs)
{
for (Class<Entity> clazz : clazzs)
belongsTo.add(clazz);
}
protected void hasAndBelongsToMany(Class<Entity>... clazzs)
{
for (Class<Entity> clazz : clazzs)
hasAndBelongsToMany.add(clazz);
}
}
public class Entity
{
protected TableMapping tlbMapping; // 与数据表的结构映射关系
protected Map<String, Object> attrs; // entity的属性
protected Set<Class<Entity>> hasOne; // 1对1
protected Set<Class<Entity>> hasMany; // 1对多
protected Set<Class<Entity>> belongsTo; // 多对1
protected Set<Class<Entity>> hasAndBelongsToMany; // 多对多
public void setAttr(String attrName, Object value)
{
attrs.put(attrName, value);
}
public Object getAttr(String attrName)
{
return attrs.get(attrName);
}
/**
* 重载这个方法,用来设置关系
*/
public void setRelation()
{
// 在这里手动的设置关系,1对1,1对多。。。
hasOne(...);
belongsTo(...);
...
}
protected void hasOne(Class<Entity>... clazzs)
{
for (Class<Entity> clazz : clazzs)
hasOne.add(clazz);
}
protected void belongsTo(Class<Entity>... clazzs)
{
for (Class<Entity> clazz : clazzs)
belongsTo.add(clazz);
}
protected void hasAndBelongsToMany(Class<Entity>... clazzs)
{
for (Class<Entity> clazz : clazzs)
hasAndBelongsToMany.add(clazz);
}
}
Java代码
public class User extends Entity
{
}
分享到:
相关推荐
5、switch语句能否作用在byte上,能否作用在long上,能否作用在String上? 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 7、char型变量中能不能存贮一个中文汉字?为什么? 8、用最有效...
5、switch语句能否作用在byte上,能否作用在long上,能否作用在String上? 9 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 9 7、char型变量中能不能存贮一个中文汉字?为什么? 9 8、用最...
5、switch语句能否作用在byte上,能否作用在long上,能否作用在String上? 9 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 9 7、char型变量中能不能存贮一个中文汉字?为什么? 9 8、用最...
5、switch语句能否作用在byte上,能否作用在long上,能否作用在String上? 9 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 9 7、char型变量中能不能存贮一个中文汉字?为什么? 9 8、用最...
5、switch语句能否作用在byte上,能否作用在long上,能否作用在String上? 9 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 9 7、char型变量中能不能存贮一个中文汉字?为什么? 9 8、用最...
5、switch语句能否作用在byte上,能否作用在long上,能否作用在String上? 9 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 9 7、char型变量中能不能存贮一个中文汉字?为什么? 9 8、用最...
5、switch语句能否作用在byte上,能否作用在long上,能否作用在String上? 9 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 9 7、char型变量中能不能存贮一个中文汉字?为什么? 9 8、用...
5、switch语句能否作用在byte上,能否作用在long上,能否作用在String上? 9 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 9 7、char型变量中能不能存贮一个中文汉字?为什么? 9 8、用最...
5、switch语句能否作用在byte上,能否作用在long上,能否作用在String上? 9 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 9 7、char型变量中能不能存贮一个中文汉字?为什么? 9 8、用最...
5、switch 语句能否作用在 byte 上,能否作用在 long 上,能否作用在 String 上? .. 9 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? ....................... 9 7、char 型变量中能不...