相关示例:
a.父类

table parent(
id
topic,
author,
entrydate,
status
)

class Parent{
int id;
String topic;
Author author;
Date entrydate;
boolean status;
}b.子类
文章表
table child_article(
parent_id,        //父类的id
summary,
body,
filename,
style,
...
)
文章类
class Article extends Parent{
String summary;
String body;
String filename;
String style;
}资源表
table child_resource(
parent_id,
summary,
filesize,
filename,
folder,
....
)
资源类
class Resource extends Parent{
String summary;
String filesize;
String filename;
String folder;
}问题描述:
我想这样显示:
a.jsp显示当月的记录(取Parent).在每条记录前面有个radio,点击查看."如果是文章就显示文章(Article),如果是资源就显示资源(根据parent的id查询具体的表)" 不知该怎么写!
根据parent的id取出的相关记录的方法(dao)写完了.如果在service中用Object的方式要转两次.(service,jsp)

解决方案 »

  1.   

    多态查询的问题。
    如果用hibernate实现的话,查出来的对象其实多是父类对象Parent.然后再用instanceof 判断是哪些子类就行了。
      

  2.   

    one to many 父子关系!可以看看hibernate对此的实践
      

  3.   

    我看你的类是一个父类,2个子类,很明显的继承关系,用hibernate做继承映射,没有关联关系的所谓一对多映射啊
      

  4.   

    我只是示例!真正的需求有10多个子类!现在卡在service层中·我没有hibernate,下面是伪代码返回值  getspecialrecord(int recordID){     switch(recordID){
              case 1:
                  articleDao.selectRelationRecord(recordID)        //这是List<article>
                  break;
              ...                                                  //下面有很多!
         }
    }
    我该怎么设计这个方法·