新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
可以通过关系映射查询出来 请看下面
网站制作、成都网站制作的开发,更需要了解用户,从用户角度来建设网站,获得较好的用户体验。创新互联建站多年互联网经验,见的多,沟通容易、能帮助客户提出的运营建议。作为成都一家网络公司,打造的就是网站建设产品直销的概念。选择创新互联建站,不只是建站,我们把建站作为产品,不断的更新、完善,让每位来访用户感受到浩方产品的价值服务。
在mybatis中,没有级联的概念,但是可以利用集合来实现类似的功能。
mybatis3.0添加了association和collection标签专门用于对多个相关实体类数据进行级联查询,但仍不支持多个相关实体类数据的级联保存和级联删除操作。因此在进行实体类多对多映射表设计时,需要专门建立一个关联对象类对相关实体类的关联关系进行描述。
插入关联表:
insert id="insertWife" useGeneratedKeys="true" keyProperty="wid" parameterType="com.cssl.pojo.Wife"
insert into wife (name,h_id) values (#{name},#{husband.hid})
/insert
关联映射:嵌入式、继承式 引入式等
先在数据库建立好主外键关系
在xml里面写一个resultMap作为返回类型,如果是多对一 用association 一对多用collection
例子
!-- 多对一 --
resultMap id="wifeandhusband" type="wife"
id property="wid" column="wid"/id
result property="wname" column="wname"/result
association property="husband" column="w_hid" javaType="com.cssl.pojo.Husband"
id property="hid" column="hid"/id
result property="name" column="name"/result
/association
/resultMap
!-- 一对多 --
resultMap id="husbandandwife" type="com.cssl.pojo.Husband"
id property="hid" column="hid"/id
result property="name" column="name"/result
collection property="wifes" ofType="wife" --ofType集合中的类型
id property="wid" column="wid"/id
result property="wname" column="wname"/result
/collection
/resultMap
select id="selectWife" resultMap="wifeandhusband"
select w.*,h.* from wife w left join husband h on w.h_id=h.hid
/select
注意:
1、关联查询一定要带有关联对象的id(主外键),否则集合只会有一条记录存在(认为你查询的是一个对象)
如:
select h.name,h.age,w.wname from wife w left join husband h on h.hid=w.h_id
2、表连接中不同表有同名字段的时候:a和b都有name字段
resultMap type="b" id="b"
id property="bid" column="id"/
result property="name" column="name"/
association property="a" javaType="a"
id property="aid" column="aid"/
result property="name" column="aname"/
/association
/resultMap
select id="select" resultMap="b"
select a.id aid,a.name aname,b.id,b.name from a,b where a.id=b.id
/select
你用什么解释xml啊,
子结点。append属性,然后父节点。append子结点啊。
#includeiostream
#includemap
using namespace std;
const int N=15e3+100;
struct node{
int v;//结点值
int l,r;//左右孩子的下标
st()
{//初始化
l=r=-1;
}
}tree[4*N];//4倍空间,用来储存二叉树
mapint,intmp;//储存数值在数组a中的下标
int a[N];//基础数组,数组tree在其基础上建树
int n=1;//1 5 8 0 0 0 6 0 0
void build_tree(int rt,int num)
{//构建二叉树
if(a[num]==0)
{//a[num]==0,表示空结点
tree[rt].v=-1;
}
else
{
if(mp.count(a[num])==0)
mp[a[num]]=rt;//储存a[num]在树中的位置
tree[rt].v=a[num];//结点赋值
num++;
build_tree(2*rt,num);//左孩子
num++;
build_tree(2*rt+1,num);//右孩子
}
}
/*
1 5 8 0 0 0 6 0 0
3
8 1 6
*/
int main()
{
int x=1,m=0;
do
{
cina[n++];//储存结点值
}
while(getchar()!='\n');//回车结束输入
build_tree(1,x);//构建二叉树(结构体数组模拟)
cinm;//查询次数
for(int i=0;im;i++)
{
int num,y;
cinnum;//查询值
y=mp[num];//mp[num]是num在tree数组中的位置,查询效率O(log2n)
y/=2;//左右孩子的下标除以2,就是父节点的下标
if(y==0)
{//父节点下标为0,既是根节点
cout0endl;
}
else
{//输出父节点值
couttree[y].vendl;
}
}
return 0;
}
程序如下供你参考.说明:
1.0 你题目中只提供了两门成绩,英语和计算机,但是下面说三门.
如果是的话,自己添加上去吧.很好修改的.
2.0 如果有什么不清楚的话,补充问题吧.或者可以给你留言.
3.0 希望你自己多看书把语言的基础知识学好.
下面共四个java类文件.
/***Student.java **/
public class Student {
protected int studentID;
protected String name;
protected int englishScore;
protected int computerScore;
protected int totalScore;
public Student(int studentID, String name) {
super();
this.studentID = studentID;
this.name = name;
}
public Student(int studentID, String name, int englishScore,
int computerScore) {
super();
this.studentID = studentID;
this.name = name;
this.englishScore = englishScore;
this点抗 puterScore = computerScore;
}
public int getStudentID() {
return studentID;
}
public void setStudentID(Integer studentID) {
this.studentID = studentID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getEnglishScore() {
return englishScore;
}
public void setEnglishScore(int englishScore) {
this.englishScore = englishScore;
}
public int getComputerScore() {
return computerScore;
}
public void setComputerScore(int computerScore) {
this点抗 puterScore = computerScore;
}
public int getTotalScore() {
return totalScore;
}
/**totalScore 没有set 方法 */
@Override
public String toString() {
return "Student [studentID=" + studentID + ", name=" + name
+ ", englishScore=" + englishScore + ", computerScore="
+ computerScore + ", totalScore=" + totalScore + "]";
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Student other = (Student) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (studentID != other.studentID)
return false;
return true;
}
/** @return 返回1 表示 大于,返回 0 表示等于, 返回-1表示小于 */
public int compare(Student other){
if(totalScore other.totalScore)
return -1; //
if(totalScore == other.totalScore)
return 0;
return 1;
}
private void sum(){
totalScore = englishScore+computerScore;
}
/**计算评测成绩 */
public double testScore(){
return (englishScore+computerScore)/2;
}
}
/***** StudentXW.java******/
public class StudentXW extends Student {
private String response;///责任
public StudentXW(int studentID, String name, String response) {
super(studentID, name);
this.response = response;
}
public StudentXW(int studentID, String name, int englishScore,
int computerScore, String response) {
super(studentID, name, englishScore, computerScore);
this.response = response;
}
public String getResponse() {
return response;
}
public void setResponse(String response) {
this.response = response;
}
@Override
public double testScore(){
return (englishScore+computerScore)/2+3;
}
}
/*****StudentBZ.java****/
public class StudentBZ extends Student {
private String response;///责任
public StudentBZ(int studentID, String name, String response) {
super(studentID, name);
this.response = response;
}
public StudentBZ(int studentID, String name, int englishScore,
int computerScore, String response) {
super(studentID, name, englishScore, computerScore);
this.response = response;
}
public String getResponse() {
return response;
}
public void setResponse(String response) {
this.response = response;
}
@Override
public double testScore(){
return (englishScore+computerScore)/2+5;
}
}
/*****测试类 TestStudent.java****/
/** Student ,StudentXW, 及StudentBZ测试类 */
public class TestStudent {
public static void main(String[] args) {
Student s1 = new Student(1,"one");
s1.setEnglishScore(80);
s1.setComputerScore(80);
StudentXW sx1 = new StudentXW(2,"xone","学习委员");
sx1.setEnglishScore(90);
sx1.setComputerScore(90);
StudentBZ sb1 = new StudentBZ(3,"bone","班长");
sb1.setEnglishScore(70);
sb1.setComputerScore(70);
System.out.println("学生 One 的评测成绩为:"+s1.testScore());
System.out.println("学生 xone,学习委员的评测成绩为:"+sx1.testScore());
System.out.println("学生 bone,班长的评测成绩为:"+sb1.testScore());
Student [] studentArray = new Student[5];
studentArray[0] = new Student(101,"studentOne",60,60);
studentArray[1] = new Student(102,"studentTwo",65,65);
studentArray[2] = new Student(103,"studentThree",70,70);
studentArray[3] = new StudentXW(104,"studentXW",75,75,"学习委员");
studentArray[4] = new StudentBZ(104,"studentXW",80,80,"学习委员");
for(Student student:studentArray){
System.out.println("名字为:"+student.getName()+"的成绩为:"+ student.testScore());
}
}
}