@Query 注解方式实现多表查询。请高手了
定义以下类
userVo1
列:id c1 c 2 c3 c4 c5
user1
列:id c1 c 2 c3
area1
列:aid c4 c5
查通过@Query的方式得到userVo对像,并返回
@Query(“select a.id,a.c1,a.c2,a.c3,b.c4,b.c5 from user a,area b where a.id=b.aid”)
public List<userVo> finduserVoList();
//user1
@Entity
@Table(name = “user”)
public class user1 {
private Long id;
private String c1;
private String c2;
private String c3;
@Id
@GenericGenerator(name = “idGenerator”, strategy = “sequence”,parameters = {@Parameter(name = “sequence”,value=”co_user_seq”)})
@GeneratedValue(generator = “idGenerator”)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getC1() {
return c1;
}
public void setC1(String c1) {
this.c1 = c1;
}
public String getC2() {
return c2;
}
public void setC2(String c2) {
this.c2 = c2;
}
public String getC3() {
return c3;
}
public void setC3(String c3) {
this.c3 = c3;
}
//area
@Entity
@Table(name = “area”)
public class area1 {
private Long aid;
private String c4;
private String c5;
@Id
@GenericGenerator(name = “idGenerator”, strategy = “sequence”,parameters = {@Parameter(name = “sequence”,value=”co_user_seq”)})
@GeneratedValue(generator = “idGenerator”)
public Long getAid() {
return aid;
}
public void setAid(Long aid) {
this.aid = aid;
}
public String getC4() {
return c4;
}
public void setC4(String c4) {
this.c4 = c4;
}
public String getC5() {
return c5;
}
public void setC5(String c5) {
this.c5 = c5;
}
//uservo1
private static final long serialVersionUID = 1L;
private Long id;
private String c1;
private String c2;
private String c3;
private String c4;
private String c5;
@Id
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getC1() {
return c1;
}
public void setC1(String c1) {
this.c1 = c1;
}
public String getC2() {
return c2;
}
public void setC2(String c2) {
this.c2 = c2;
}
public String getC3() {
return c3;
}
public void setC3(String c3) {
this.c3 = c3;
}
public String getC4() {
return c4;
}
public void setC4(String c4) {
this.c4 = c4;
}
public String getC5() {
return c5;
}
public void setC5(String c5) {
this.c5 = c5;
}
定义以下类
userVo1
列:id c1 c 2 c3 c4 c5
user1
列:id c1 c 2 c3
area1
列:aid c4 c5
查通过@Query的方式得到userVo对像,并返回
@Query(“select a.id,a.c1,a.c2,a.c3,b.c4,b.c5 from user a,area b where a.id=b.aid”)
public List<userVo> finduserVoList();
//user1
@Entity
@Table(name = “user”)
public class user1 {
private Long id;
private String c1;
private String c2;
private String c3;
@Id
@GenericGenerator(name = “idGenerator”, strategy = “sequence”,parameters = {@Parameter(name = “sequence”,value=”co_user_seq”)})
@GeneratedValue(generator = “idGenerator”)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getC1() {
return c1;
}
public void setC1(String c1) {
this.c1 = c1;
}
public String getC2() {
return c2;
}
public void setC2(String c2) {
this.c2 = c2;
}
public String getC3() {
return c3;
}
public void setC3(String c3) {
this.c3 = c3;
}
//area
@Entity
@Table(name = “area”)
public class area1 {
private Long aid;
private String c4;
private String c5;
@Id
@GenericGenerator(name = “idGenerator”, strategy = “sequence”,parameters = {@Parameter(name = “sequence”,value=”co_user_seq”)})
@GeneratedValue(generator = “idGenerator”)
public Long getAid() {
return aid;
}
public void setAid(Long aid) {
this.aid = aid;
}
public String getC4() {
return c4;
}
public void setC4(String c4) {
this.c4 = c4;
}
public String getC5() {
return c5;
}
public void setC5(String c5) {
this.c5 = c5;
}
//uservo1
private static final long serialVersionUID = 1L;
private Long id;
private String c1;
private String c2;
private String c3;
private String c4;
private String c5;
@Id
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getC1() {
return c1;
}
public void setC1(String c1) {
this.c1 = c1;
}
public String getC2() {
return c2;
}
public void setC2(String c2) {
this.c2 = c2;
}
public String getC3() {
return c3;
}
public void setC3(String c3) {
this.c3 = c3;
}
public String getC4() {
return c4;
}
public void setC4(String c4) {
this.c4 = c4;
}
public String getC5() {
return c5;
}
public void setC5(String c5) {
this.c5 = c5;
}
解决方案
40
講的不清不楚,說明白點