Mybatis将List<T> 作为参数

实体类文件:Map.cs与UserInfo.cs

[Serializable] 
 public class Map
{
  public string UserID { get; set; }
       public string UserGroup { get; set; }
 }

 

[Serializable] 
public class UserInfo
{ 
      public string UserID { get; set; }
 
      public string CardWord { get; set; }
 
      public string UserName { get; set; }
 
      public string PassWord { get; set; }
 
      public string UserPicture { get; set; }
 
      public string UserMail { get; set; }
 
      public DateTime RegTime { get; set; }
 
      public string UserStatus { get; set; }
 }

 xml文件中的配置,此处只给出涉及到的必要代码,数据库中的表名userinfo

<!--省略非必要代码-->
<resultMaps>
     <resultMap id="SelectAllUser" class="UserInfo">
        <result property="UserID" column="ID"/>
        <result property="CardWord" column="Card_Word"/>
        <result property="UserName" column="User_Name"/>
        <result property="PassWord" column="Pass_Word"/>
        <result property="UserPicture" column="User_Picture"/>
        <result property="UserMail" column="User_Mail"/>
        <result property="RegTime" column="Reg_Time"/>
        <result property="UserStatus" column="User_Status"/>
      </resultMap> 
  </resultMaps>
<!--省略非必要代码-->
<statements>
<!--获取好友信息-->
    <select id="GetAllUserByID" resultMap="SelectAllUser" parameterClass="List"> 
        select * from userinfo where ID in 
          <iterate conjunction="," open="(" close=")">  
             #[].UserID# 
          </iterate>  
    </select>
</statements>
<!--省略非必要代码-->

调用代码

List<Map> hashTable = new List<Map>();
List<Userinfo> userList = null;
userList = mapper.QueryForList<UserInfo>("GetAllUserByID", hashTable).ToList();

 

posted @ 2015-03-20 16:12  streamice  阅读(1553)  评论(0编辑  收藏  举报