首页 新闻 赞助 找找看

关于Ibatis.net 将List<T> 作为参数的,怎么也不成功

0
悬赏园豆:10 [已解决问题] 解决于 2013-10-12 10:03

类文件Map.cs

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

类文件UserInfo.cs

[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="System.Collections.Generic.List">
      <![CDATA[select ID,Card_Word,User_Name,Pass_Word,User_Picture,User_Mail,Reg_Time,User_Status 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();

错误提示:

- The error occurred while loading SqlMap.

- loading select tag

- The error occurred in

- Check the GetAllUserByID.

各位,有何见解。。。

u1s10的主页 u1s10 | 初学一级 | 园豆:183
提问于:2013-10-09 11:48
< >
分享
最佳答案
0
<select id="GetAllUserByID" resultMap="SelectAllUser" parameterClass="List"> 
        select * from userinfo where ID in 
          <iterate conjunction="," open="(" close=")">  
             #[].UserID# 
          </iterate>  
    </select>

 搞定!!!

u1s10 | 初学一级 |园豆:183 | 2013-10-12 10:02
其他回答(2)
0

首先,我没这样用过;

再者,你可以用exec(@sql)的方式实现。

收获园豆:10
幻天芒 | 园豆:37175 (高人七级) | 2013-10-09 13:12

刚看了看Ibatis.net的帮助文档,单纯作为参数方面,List只支持System.ArrayList与System.Hashtable,看来只能变通方法了

支持(0) 反对(0) u1s10 | 园豆:183 (初学一级) | 2013-10-09 16:05

@Smlusm: 呵呵,那就换实现思路了。

支持(0) 反对(0) 幻天芒 | 园豆:37175 (高人七级) | 2013-10-09 21:07

@幻天芒:你的那个算是拼字符串吧,学习了,

               _(_)_                        wWWWw
   @@@@       (_)@(_)  vVVVv    _     @@@@  (___)
  @@()@@ wWWWw  (_)\   (___)  _(_)_  @@()@@   Y
   @@@@  (___)     `|/   Y   (_)@(_)  @@@@   \|/
    /      Y       \|   \|/   /(_)    \|      |/
 \ |     \ |/       | /\ | / \|/       |/    \|
   |///  \\|/// \\\\|//\\|///\|///  \\\|//  \\|//
^^^^^^ 百 ^^^^^^^^^^^^^ 花 ^^^^^^^^^^^^^^^ 园 ^^^^^

 

支持(0) 反对(0) 幻天芒 | 园豆:37175 (高人七级) | 2013-10-12 13:07
0

兄弟如果累了.

看看http://www.cnblogs.com/humble/p/3320804.html

迅捷网络[来送福利] | 园豆:616 (小虾三级) | 2013-10-09 17:56
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册