学生类 一方public class Student implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private Integer sid;
private String sno;
private String studentname;
private String password;
private Set cours;
//...set get}
<hibernate-mapping package="com.free.exam.domain">
<class name="Student" table="fe_student">
<id name="sid" type="integer">
<column name="sid" />
<generator class="native" />
</id>
<property name="sno" column="sno" />
<property name="studentname" column="studentname" />
<property name="password" column="password" />
<set name="cours" cascade="all"
lazy="false" >
<key column="sid" />
<one-to-many class="Course"/>
</set>
</class>
</hibernate-mapping>
学生表字段名: sid sno studentname password##创建学生表
drop table fe_student;
create table fe_student(
sid int not null auto_increment,
sno varchar (20),
studentname varchar(50),
password varchar(50),
primary key (sid)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;insert into fe_student values(1,'078325023','邱文彬','gnzLDuqKcGxMNKFokfhOew==');
insert into fe_student values(2,'078325032','晓晓','gnzLDuqKcGxMNKFokfhOew==');多方 Coursepackage com.free.exam.domain;public class Course implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private Integer cno;
// private String sno;
private String coursename;
private Integer score;
private Student student;
//set 。get....
}Course.hbm.xml<hibernate-mapping package="com.free.exam.domain">
<class name="Course" table="fe_course">
<id name="cno" column="cno">
<generator class="native" />
</id>
<property name="coursename" column="coursename" />
<property name="score" column="score" />
<many-to-one name="student"
column="sid"
lazy="false"
/>
</class>
</hibernate-mapping>
Course表 字段:cno sid coursename score --考试科目表
drop table fe_course;
CREATE TABLE `fe_course` (
`cno` int(11) NOT NULL auto_increment,
`sid` int(11) default NULL,
`coursename` varchar(255) default NULL,
`score` int(11) default NULL,
PRIMARY KEY (`cno`),
KEY `FK5FCDCB9B878B7AB9` (`sid`),
CONSTRAINT `FK5FCDCB9B878B7AB9` FOREIGN KEY (`sid`) REFERENCES `fe_student` (`sid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;insert into fe_course values(null,1,'JAVA',77);
insert into fe_course values(null,1,'ASP',55);
insert into fe_course values(null,1,'C#',99);
insert into fe_course values(null,1,'C++',66);
insert into fe_course values(null,1,'C',88);
insert into fe_course values(null,1,'VB',44);
insert into fe_course values(null,1,'VFP',65);insert into fe_course values(null,2,'JAVA',99);
insert into fe_course values(null,2,'ASP',88);
insert into fe_course values(null,2,'C#',94);
insert into fe_course values(null,2,'C++',77);
insert into fe_course values(null,2,'C',85);
insert into fe_course values(null,2,'VB',66);
insert into fe_course values(null,2,'VFP',78);
我的jsp页面还没写 先简单讲下需求 就是<foreach item="...list" ><table>.... </table></foreach>,请问大大 怎么用hql 查上面2表得出集合结果放到item里的...list 供页面循环输出,table表头是 studentname score 就行了。
private static final long serialVersionUID = 1L;
private Integer sid;
private String sno;
private String studentname;
private String password;
private Set cours;
//...set get}
<hibernate-mapping package="com.free.exam.domain">
<class name="Student" table="fe_student">
<id name="sid" type="integer">
<column name="sid" />
<generator class="native" />
</id>
<property name="sno" column="sno" />
<property name="studentname" column="studentname" />
<property name="password" column="password" />
<set name="cours" cascade="all"
lazy="false" >
<key column="sid" />
<one-to-many class="Course"/>
</set>
</class>
</hibernate-mapping>
学生表字段名: sid sno studentname password##创建学生表
drop table fe_student;
create table fe_student(
sid int not null auto_increment,
sno varchar (20),
studentname varchar(50),
password varchar(50),
primary key (sid)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;insert into fe_student values(1,'078325023','邱文彬','gnzLDuqKcGxMNKFokfhOew==');
insert into fe_student values(2,'078325032','晓晓','gnzLDuqKcGxMNKFokfhOew==');多方 Coursepackage com.free.exam.domain;public class Course implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private Integer cno;
// private String sno;
private String coursename;
private Integer score;
private Student student;
//set 。get....
}Course.hbm.xml<hibernate-mapping package="com.free.exam.domain">
<class name="Course" table="fe_course">
<id name="cno" column="cno">
<generator class="native" />
</id>
<property name="coursename" column="coursename" />
<property name="score" column="score" />
<many-to-one name="student"
column="sid"
lazy="false"
/>
</class>
</hibernate-mapping>
Course表 字段:cno sid coursename score --考试科目表
drop table fe_course;
CREATE TABLE `fe_course` (
`cno` int(11) NOT NULL auto_increment,
`sid` int(11) default NULL,
`coursename` varchar(255) default NULL,
`score` int(11) default NULL,
PRIMARY KEY (`cno`),
KEY `FK5FCDCB9B878B7AB9` (`sid`),
CONSTRAINT `FK5FCDCB9B878B7AB9` FOREIGN KEY (`sid`) REFERENCES `fe_student` (`sid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;insert into fe_course values(null,1,'JAVA',77);
insert into fe_course values(null,1,'ASP',55);
insert into fe_course values(null,1,'C#',99);
insert into fe_course values(null,1,'C++',66);
insert into fe_course values(null,1,'C',88);
insert into fe_course values(null,1,'VB',44);
insert into fe_course values(null,1,'VFP',65);insert into fe_course values(null,2,'JAVA',99);
insert into fe_course values(null,2,'ASP',88);
insert into fe_course values(null,2,'C#',94);
insert into fe_course values(null,2,'C++',77);
insert into fe_course values(null,2,'C',85);
insert into fe_course values(null,2,'VB',66);
insert into fe_course values(null,2,'VFP',78);
我的jsp页面还没写 先简单讲下需求 就是<foreach item="...list" ><table>.... </table></foreach>,请问大大 怎么用hql 查上面2表得出集合结果放到item里的...list 供页面循环输出,table表头是 studentname score 就行了。
解决方案 »
- javaMail发送邮件错误:Could not connect to SMTP host: pop.sina.com
- 莫名其妙的 java.lang.NoSuchMethodError
- javascript怎么验证文件名是否合法,急等
- tomcat http://localhost:8080 打不开
- eclipse3.3+myeclipse6.0.1配置错误?--求助!
- ■■ 有关session的问题。。。急,谢谢(在线等)
- jsf的刷新问题.
- Invocation of init method failed; nested exception is java.lang.NullPointerExcep
- 为什么编译servlet的时候出现这样的错误,在线等待,谢谢
- 请问,在JSP中,<%@ include file="a.jsp" %>和<JSP:include page="a.jsp" />有什么区别呢?
- 用myeclipse进行web开发的时候遇到的问题,求解答
- HTTP Status 500 错误,求高手拯救!不胜感激
select
studentname Coursename
from
student as stu
inner join
Course as cou
on(stu.sid = cou.sid)
返回的结果集 就可以根据你的需要使用了...
studentname Coursename
from
student as stu
inner join
Course as cou
on(stu.sid = cou.sid)