allenyushuo
never222
采纳率0%
2015-02-04 05:25 阅读 913

mybatis.net 向数据库插入数据问题

有一个UserInfo表ID为主键 自增长
在xml文件中

<resultMaps>
<!--UserInfoModel类与db表的映射-->
<resultMap id="SelectAllResult" class="UserInfo">
  <result property="ID" column="ID"/>
  <result property="UserID" column="UserID"/>
  <result property="Name" column="Name" />
  <result property="Password" column="Password"/>
  <result property="Mail" column="Mail" />
  <result property="Phone" column="Phone" />
  <result property="Address" column="Address" />
  <result property="CreateTime" column="CreateTime" />
  <result property="Enable" column="Enable" />
</resultMap>

<!--插入新记录-->
<insert id="InsertUserInfo" parameterClass="UserInfo">
  <!--sql 主键的示例用法-->
  <selectKey resultClass="int" type="post" keyProperty="ID">
    select @@IDENTITY as value
  </selectKey>
  <![CDATA[
  INSERT into UserInfo
  (UserID,
   Name,
   Password,
   Mail,
   Phone,
   Address,
   CreateTime,
   Enable)
   VALUES
   (#UserID#,
   #Name#,
   #Password# ,
   #Mail# ,
   #Phone#,
   #Address#,
   #CreateTime#,
   #Enable#)
   ]]>
</insert>

    前台测试
    public void InsertUserInfo()
    {
        UserInfoModel userInfo=new UserInfoModel();

        userInfo.Address = "南京";
        userInfo.CreateTime = DateTime.Now;
        userInfo.Name = "于硕AAA";
        userInfo.Mail = "12245@qq.com";
        userInfo.UserID = "cast";
        userInfo.Password = "zte@2014";
        userInfo.Phone = "15961820351";
        userInfo.Enable = true;
        _batisDao.Insert("InsertUserInfo", userInfo);

    }

    代码运行的时候总是报这个错误,但是数据库中数据已经插入了 请问下是什么情况
    There is no Set member named '' in class 'UserInfoModel'
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • gglstudy2 gglstudy2 2020-10-19 17:32

    将selectKey子元素的keyProperty”改为“property”,就正常了。

    点赞 评论 复制链接分享

相关推荐