TRACK為多表,BAR為一表//注意類的包含關(guān)系
xml文件如下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "sql-map-2.dtd">
<sqlMap namespace="TrackBar">
?<typeAlias alias="TrackBar" type="edu.hit.ice.ibatis.domain.TrackBar"/>
? ?
? ?<cacheModel id="trackBarCache" type="LRU">
???? <flushInterval hours="24"/>
???? <property name="size" value="100"/>
??? </cacheModel>
??? <select id="selectTrackBar" resultClass="TrackBar" parameterClass="java.lang.String" cacheModel="trackBarCache">
??? ?select HASH,ACCOUNT,START_TIME,END_TIME,REGION_NUM,CITY_NUM,LOCAL_IP,
??? ??????? BAR.BAR_ID as "bar.BAR_ID",
??? ??????? BAR.BAR_NAME as "bar.BAR_NAME",
??? ??????? TRACK_CARD_4419_200605_2.BAR_NUM as "bar.BAR_NUM"
??????? from BAR,track_card_4419_200605_2
??????? where BAR.BAR_NUM=TRACK_CARD_4419_200605_2.BAR_NUM
????????????? AND BAR.BAR_NUM=#value#
??? </select>
???
??? <!-- 一對多關(guān)系,tablename[]的屬性中包括bar類-->
?? <statement id="selectBarUnion" parameterClass="edu.hit.ice.ibatis.domain.TrackList"? resultClass="edu.hit.ice.ibatis.domain.TrackBar">
?? select * from (
?? <dynamic prepend="">
???? <iterate prepend="" property="tablename" conjunction="union"? open="(" close=")" >??
????? (select HASH,ACCOUNT,START_TIME,END_TIME,REGION_NUM,CITY_NUM,LOCAL_IP,
??? ??????? BAR.BAR_ID as "bar.BAR_ID",
??? ??????? BAR.BAR_NAME as "bar.BAR_NAME",
??? ??????? $tablename[]$.BAR_NUM as "bar.BAR_NUM"
?????? from $tablename[]$,BAR?
??????? <isNotNull prepend="where" property="BAR_NUM">??
???????????? ?$tablename[]$.BAR_NUM=#BAR_NUM#
???????????? </isNotNull>???????
????????????
???????????? ?and BAR.BAR_NUM=$tablename[]$.BAR_NUM???????
?????? )
?????
????? </iterate>
?? </dynamic>
?? ) as b
? </statement>
????
</sqlMap>
TRACKBAR表對應(yīng)的類:
package edu.hit.ice.ibatis.domain;
public class TrackBar {
?private String HASH;
?private String ACCOUNT;
?private Integer START_TIME;
?private Integer END_TIME;?
?private Short REGION_NUM;
?private Short CITY_NUM;
?private String BAR_NUM;?
?private Integer LOCAL_IP;
?
//?注意這個地方
?private Bar bar;
?public String getHASH() {
??return HASH;
?}?
?
?public void setHASH(String HASH) {
??if (HASH != null) {
???HASH = HASH.trim();
??}
??this.HASH = HASH;
?}
?
?public String getACCOUNT() {
??return ACCOUNT;
?}?
?
?public void setACCOUNT(String ACCOUNT) {
??if (ACCOUNT != null) {
???ACCOUNT = ACCOUNT.trim();
??}
??this.ACCOUNT = ACCOUNT;
?}?
?
?public void setSTART_TIME(Integer START_TIME) {
??this.START_TIME = START_TIME;
?}
?
?public Integer getSTART_TIME()
?{
??return START_TIME;
?}
?
?public void setEND_TIME(Integer END_TIME) {
??this.END_TIME = END_TIME;
?}
?
?public Integer getEND_TIME() {
??return END_TIME;
?}
?public Short getREGION_NUM() {
??return REGION_NUM;
?}
?public void setREGION_NUM(Short REGION_NUM) {
??this.REGION_NUM = REGION_NUM;
?}
?public Short getCITY_NUM() {
??return CITY_NUM;
?}
?public void setCITY_NUM(Short CITY_NUM) {
??this.CITY_NUM= CITY_NUM;
?}
?public String getBAR_NUM() {
??return BAR_NUM;
?}
?public void setBAR_NUM(String BAR_NUM) {
??if (BAR_NUM != null) {
???BAR_NUM = BAR_NUM.trim();
??}
??this.BAR_NUM = BAR_NUM;
?}
?public Integer getLOCAL_IP() {
??return LOCAL_IP;
?}
?public void setLOCAL_IP(Integer LOCAL_IP) {
??this.LOCAL_IP = LOCAL_IP;
?}
?
?public Bar getBar()
?{
??return bar;
?}
?
?public void setBar(Bar bar)
?{
??this.bar=bar;
?}
}
BAR表對應(yīng)的類:
package edu.hit.ice.ibatis.domain;
import java.util.List;
public class Bar {
?/**
? * @param args
? */
?private int?? BAR_ID;
?
?private String BAR_NUM;
?private String BAR_NAME;
?
? public int gerBAR_ID()
???? {
???? ?return this.BAR_ID;
???? }
???? public void setBAR_ID(int BAR_ID)
???? {
???? ?this.BAR_ID=BAR_ID;
???? }
??
?public void setBAR_NUM(String BAR_NUM)
?{
??this.BAR_NUM=BAR_NUM;
?}
?public String getBAR_NUM()
?{
??return this.BAR_NUM;
?}
?public void setBAR_NAME(String BAR_NAME)
?{
??this.BAR_NAME=BAR_NAME;
?}
?public String getBAR_NAME()
?{
??return this.BAR_NAME;
?}
?
??
?
}
TrackList類是輸入類:
package edu.hit.ice.ibatis.domain;
import java.util.*;
/*由Track類和一個table的list組成的類,用來測試個表查詢結(jié)果的union*/
public class TrackList {
?/**
? * This field was generated by Abator for iBATIS. This field corresponds to the database column virtual_human.track_card_4419_200604_2.HASH
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?private List tablename;
?private String HASH;
?/**
? * This field was generated by Abator for iBATIS. This field corresponds to the database column virtual_human.track_card_4419_200604_2.ACCOUNT
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?private String ACCOUNT;
?/**
? * This field was generated by Abator for iBATIS. This field corresponds to the database column virtual_human.track_card_4419_200604_2.START_TIME
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?private Integer START_TIME;
?/**
? * This field was generated by Abator for iBATIS. This field corresponds to the database column virtual_human.track_card_4419_200604_2.END_TIME
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?private Integer END_TIME;
?/**
? * This field was generated by Abator for iBATIS. This field corresponds to the database column virtual_human.track_card_4419_200604_2.REGION_NUM
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?private Short REGION_NUM;
?private Short CITY_NUM;
?/**
? * This field was generated by Abator for iBATIS. This field corresponds to the database column virtual_human.track_card_4419_200604_2.BAR_NUM
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?private String BAR_NUM;
?/**
? * This field was generated by Abator for iBATIS. This field corresponds to the database column virtual_human.track_card_4419_200604_2.LOCAL_IP
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?private Integer LOCAL_IP;
?public List gettablename() {
??return this.tablename;
?}
?/**
? * This method was generated by Abator for iBATIS. This method sets the value of the database column virtual_human.track_card_4419_200604_2.HASH
? * @param HASH? the value for virtual_human.track_card_4419_200604_2.HASH
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?public void settablename(List tablename) {
??
??this.tablename =tablename;
?}
?/**
? * This method was generated by Abator for iBATIS. This method returns the value of the database column virtual_human.track_card_4419_200604_2.HASH
? * @return? the value of virtual_human.track_card_4419_200604_2.HASH
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?public String getHASH() {
??return HASH;
?}
?/**
? * This method was generated by Abator for iBATIS. This method sets the value of the database column virtual_human.track_card_4419_200604_2.HASH
? * @param HASH? the value for virtual_human.track_card_4419_200604_2.HASH
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?public void setHASH(String HASH) {
??if (HASH != null) {
???HASH = HASH.trim();
??}
??this.HASH = HASH;
?}
?/**
? * This method was generated by Abator for iBATIS. This method returns the value of the database column virtual_human.track_card_4419_200604_2.ACCOUNT
? * @return? the value of virtual_human.track_card_4419_200604_2.ACCOUNT
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?public String getACCOUNT() {
??return ACCOUNT;
?}
?/**
? * This method was generated by Abator for iBATIS. This method sets the value of the database column virtual_human.track_card_4419_200604_2.ACCOUNT
? * @param ACCOUNT? the value for virtual_human.track_card_4419_200604_2.ACCOUNT
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?public void setACCOUNT(String ACCOUNT) {
??if (ACCOUNT != null) {
???ACCOUNT = ACCOUNT.trim();
??}
??this.ACCOUNT = ACCOUNT;
?}
?/**
? * This method was generated by Abator for iBATIS. This method returns the value of the database column virtual_human.track_card_4419_200604_2.START_TIME
? * @return? the value of virtual_human.track_card_4419_200604_2.START_TIME
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?public Integer getSTART_TIME() {
??return START_TIME;
?}
?/**
? * This method was generated by Abator for iBATIS. This method sets the value of the database column virtual_human.track_card_4419_200604_2.START_TIME
? * @param START_TIME? the value for virtual_human.track_card_4419_200604_2.START_TIME
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?public void setSTART_TIME(Integer START_TIME) {
??this.START_TIME = START_TIME;
?}
?/**
? * This method was generated by Abator for iBATIS. This method returns the value of the database column virtual_human.track_card_4419_200604_2.END_TIME
? * @return? the value of virtual_human.track_card_4419_200604_2.END_TIME
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?public Integer getEND_TIME() {
??return END_TIME;
?}
?/**
? * This method was generated by Abator for iBATIS. This method sets the value of the database column virtual_human.track_card_4419_200604_2.END_TIME
? * @param long1? the value for virtual_human.track_card_4419_200604_2.END_TIME
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?public void setEND_TIME(Long long1) {
??this.END_TIME = END_TIME;
?}
?/**
? * This method was generated by Abator for iBATIS. This method returns the value of the database column virtual_human.track_card_4419_200604_2.REGION_NUM
? * @return? the value of virtual_human.track_card_4419_200604_2.REGION_NUM
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?public Short getREGION_NUM() {
??return REGION_NUM;
?}
?/**
? * This method was generated by Abator for iBATIS. This method sets the value of the database column virtual_human.track_card_4419_200604_2.REGION_NUM
? * @param REGION_NUM? the value for virtual_human.track_card_4419_200604_2.REGION_NUM
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?public void setREGION_NUM(Short REGION_NUM) {
??this.REGION_NUM = REGION_NUM;
?}
?/**
? * This method was generated by Abator for iBATIS. This method returns the value of the database column virtual_human.track_card_4419_200604_2.BAR_NUM
? * @return? the value of virtual_human.track_card_4419_200604_2.BAR_NUM
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?public Short getCITY_NUM() {
??return CITY_NUM;
?}
?/**
? * This method was generated by Abator for iBATIS. This method sets the value of the database column virtual_human.track_card_4419_200604_2.REGION_NUM
? * @param REGION_NUM? the value for virtual_human.track_card_4419_200604_2.REGION_NUM
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?public void setCITY_NUM(Short CITY_NUM) {
??this.CITY_NUM= CITY_NUM;
?}
?/**
? * This method was generated by Abator for iBATIS. This method returns the value of the database column virtual_human.track_card_4419_200604_2.BAR_NUM
? * @return? the value of virtual_human.track_card_4419_200604_2.BAR_NUM
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?
?public String getBAR_NUM() {
??return BAR_NUM;
?}
?/**
? * This method was generated by Abator for iBATIS. This method sets the value of the database column virtual_human.track_card_4419_200604_2.BAR_NUM
? * @param BAR_NUM? the value for virtual_human.track_card_4419_200604_2.BAR_NUM
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?public void setBAR_NUM(String BAR_NUM) {
??if (BAR_NUM != null) {
???BAR_NUM = BAR_NUM.trim();
??}
??this.BAR_NUM = BAR_NUM;
?}
?/**
? * This method was generated by Abator for iBATIS. This method returns the value of the database column virtual_human.track_card_4419_200604_2.LOCAL_IP
? * @return? the value of virtual_human.track_card_4419_200604_2.LOCAL_IP
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?public Integer getLOCAL_IP() {
??return LOCAL_IP;
?}
?/**
? * This method was generated by Abator for iBATIS. This method sets the value of the database column virtual_human.track_card_4419_200604_2.LOCAL_IP
? * @param LOCAL_IP? the value for virtual_human.track_card_4419_200604_2.LOCAL_IP
? * @abatorgenerated? Thu Dec 15 10:58:34 CST 2005
? */
?public void setLOCAL_IP(Integer LOCAL_IP) {
??this.LOCAL_IP = LOCAL_IP;
?}
}