ibatis中resultMap映射

1: ibatis配置文件

 

<typeAlias alias="webUser" type="com.model.WebUser" />

 

<resultMap id="get-user-result" class="webUser">
  <result property="uid" column="UID" />
  <result property="uno" column="UNo" />
  <result property="uname" column="UName" />
  <result property="pswd" column="Pswd" />
  <result property="sidType" column="SID" />
  <result property="dn" column="DN" />
  <result property="role" column="RoleId" select="wbst_webRole.getRoleById"/>
  <result property="brNo" column="SysAuxCode" />
  <result property="stateType" column="State" />

 

 // 看 还可以用这种方式赋值呢哦 


  <result property="member" column="CltNo" select="wbst_member.getMemberByNo"/>
  <result property="userActionType" column="Action" />
  <result property="firstEnterType" column="FirstEnter" />
  <result property="webContentUser" column="UID" select="wbst_webContent.getLastContentByUserSource" />
  <result property="activeType" column="Active" />
  <result property="rejectType" column="{sourceId=UID,action=action}" select="wbst_webContent.getRejectByUser"/>
 </resultMap>
 
 <select id="getUserById" parameterClass="int" resultMap="get-user-result">
  select * from wfuser where "UID"=#value#
 </select>

 

2: webUser类

 

public class WebUser implements Serializable {
 protected Integer uid;
 protected String uno;
 protected String uname;
 protected String pswd;
 protected UserState sid;
 protected String dn;
 protected WebRole role;
  protected String brNo;
 protected OpenState state;
 protected Member member;
 protected UserAction userAction;
 protected FirstEnter firstEnter;
 protected WebContentUser webContentUser;
 protected Activated active;
 private Reject reject;
 
 public WebUser(){
  
 }
 
 public Reject getReject() {
  return reject;
 }

 public void setReject(Reject reject) {
  this.reject = reject;
 }
 
 public void setRejectType(Integer reject) {
  if(reject == null)
   return ;
  this.reject = Reject.getType(reject);
 }

 public WebContentUser getWebContentUser() {
  return webContentUser;
 }

 public void setWebContentUser(WebContentUser webContentUser) {
  this.webContentUser = webContentUser;
 }

 public Activated getActive() {
  return active;
 }

 public void setActive(Activated active) {
  this.active = active;
 }
 

// 通过如下这种方式未active类赋值,active为枚举类在下面会有介绍

 


 public void setActiveType(Integer active) {
  if(active == null)
   return;
  this.active = Activated.getType(active);
 }

 public OpenState getState() {
  return state;
 }

 public void setState(OpenState state) {
  this.state = state;
 }
 
 public void setStateType(Integer state) {
  if(state == null)
   return;
  this.state = OpenState.getType(state);
 }

 public FirstEnter getFirstEnter() {
  return firstEnter;
 }

 public void setFirstEnter(FirstEnter firstEnter) {
  this.firstEnter = firstEnter;
 }
 
 public void setFirstEnterType(Integer firstEnter) {
  if(firstEnter == null)
   return;
  this.firstEnter = FirstEnter.getType(firstEnter);
 }

 public UserAction getUserAction() {
  return userAction;
 }

 public void setUserAction(UserAction userAction) {
  this.userAction = userAction;
 }

 public void setUserActionType(Integer userAction) {
  if(userAction == null)
   return ;
  this.userAction = UserAction.getType(userAction);
 }
 
 public Member getMember() {
  return member;
 }

 public void setMember(Member member) {
  this.member = member;
 }

 public String getPswd() {
  return pswd;
 }

 public void setPswd(String pswd) {
  this.pswd = pswd;
 }

 public UserState getSid() {
  return sid;
 }

 public void setSid(UserState sid) {
  this.sid = sid;
 }
 
 public void setSidType(Integer sid){
  if(sid == null)
   return;
  this.sid=UserState.getType(sid);
 }

 public String getBrNo() {
  return brNo;
 }

 public void setBrNo(String brNo) {
  this.brNo = brNo;
 }

 public String getDn() {
  return dn;
 }

 public void setDn(String dn) {
  this.dn = dn;
 }

 public WebRole getRole() {
  return role;
 }

 public void setRole(WebRole role) {
  this.role = role;
 }

 public Integer getUid() {
  return uid;
 }

 public void setUid(Integer uid) {
  this.uid = uid;
 }

 public String getUname() {
  return uname;
 }

 public void setUname(String uname) {
  this.uname = uname;
 }

 public String getUno() {
  return uno;
 }

 public void setUno(String uno) {
  this.uno = uno;
 }
 
 public String toString(){
  return "{UID=" + getUid() + " : UNo=" + getUno() + "\n\r" + " : UName="
    + getUname() + "}\n\r" + getRole() + "\n" + getMember()
    + "\n\r" + getSid();
 }
}

 

 

3: 在类加载时静态变量被加载,并初始化map的值了。

public class Activated extends EnumerateType{
 private static TreeMap map = new TreeMap();

 private Activated(int code, String text) {
  super(String.valueOf(code), text);
  map.put(getCode(), this);
 }

 /**
  * 根据类型号返回类型对象。
  */
 public static Activated getType(Integer code) {
  return (Activated) map.get(String.valueOf(code));
 }

 public static Activated getType(int code) {
  return (Activated) map.get(String.valueOf(code));
 }

 /**
  * 取全部类型列表
  */
 public static Activated[] getTypeList() {
  Activated[] list = new Activated[map.size()];
  map.values().toArray(list);
  return list;
 }

 /** 0:未激活 */
 public static Activated USER_NONACTIVATED = new Activated(0, "未激活");
 /** 1:已激活 */
 public static Activated USER_ACTIVATED = new Activated(1, "已激活");
}

 

 

 

4:所有枚举类的父类

 

public class EnumerateType
/*    */   implements Serializable, Comparable, OptionObject
/*    */ {
/*    */   private String code;
/*    */   private String text;
/*    */
/*    */   protected EnumerateType(String code, String text)
/*    */   {
/* 24 */     this.code = code;
/* 25 */     this.text = text;
/*    */   }
/*    */
/*    */   public String getCode()
/*    */   {
/* 33 */     return this.code;
/*    */   }
/*    */
/*    */   public String getValue()
/*    */   {
/* 41 */     return this.code;
/*    */   }
/*    */
/*    */   public String getText()
/*    */   {
/* 49 */     return this.text;
/*    */   }
/*    */
/*    */   public int compareTo(Object o)
/*    */   {
/* 58 */     EnumerateType type = (EnumerateType)o;
/* 59 */     return getCode().compareTo(type.getCode());
/*    */   }
/*    */
/*    */   public boolean equals(Object o)
/*    */   {
/* 68 */     if (o == this) {
/* 69 */       return true;
/*    */     }
/* 71 */     if (o instanceof EnumerateType) {
/* 72 */       EnumerateType type = (EnumerateType)o;
/* 73 */       return (type.getCode() == getCode());
/*    */     }
/* 75 */     return false;
/*    */   }
/*    */
/*    */   public int hashCode()
/*    */   {
/* 84 */     return this.code.hashCode();
/*    */   }
/*    */
/*    */   public String toString()
/*    */   {
/* 92 */     return "code=" + this.code + " , " + "text=" + this.text;
/*    */   }
/*    */ }

你可能感兴趣的:(ibatis)