ibatis中resultClass与resultMap 的区别

ibatis的resultClass与resultMap还是有很大的区别。以下是我碰到的一个问题。 配置文件写法如下: 1 sqlMap2 typeAlias alias="notice" type="path.country.basic.entity.Notice"/3 resultMap id={% ...   ibatis的resultClass与resultMap还是有很大的区别。以下是我碰到的一个问题。
     配置文件写法如下:    
 1 <sqlMap>
 2     <typeAlias alias="notice" type="path.country.basic.entity.Notice"/>
 3     <resultMap id="noticeResult" class="notice" >
 4         <result property="id" column="MainID"/>
 5         <result property="content" column="Notice_Content"/>
 6         <result property="isUsed" column="Notice_IsUsed"/>
 7         <result property="createMan" column="CreateId"/>
 8         <result property="createDate" column="CreateDate"/>
 9         <result property="createIp" column="CreateIP" />
10         <result property="lastModifyMan" column="ModifyId"/>
11         <result property="lastModifyDate" column="ModifyDate" />
12         <result property="lastModifyIp" column="ModifyIP" />
13         <result property="manName" column="CreateId" select="getUserNameById"/>
14     </resultMap>
15      <select id="getNewNotice" resultClass="notice">
16         SELECT *  FROM Bse_Notice WHERE Notice_IsUsed='1'
17     </select>
18  </sqlMap>
      在前台调用时,对象是取到了,但是里面的属性值为空。
      查了相关资料才知道:resultclass属于隐身映射,虽然你指定resultclass=“”,具体某一个类,但是select语句得到的结果是一 条实力记录,但如果数据库字段与类的属性名字不一致,这个时候就会出现映射错误,有一种方式可以解决就是在写select语句时,给每个字段用as运算符 取名字与属性一样:例如:select realname as name...其中realname是字段列名,name是属性字段名。
      当然解决问题还是很容易的,只需要把resultClass改为resultMap就行了。
      在性能方面,resultMap要比resultClass高,所以建议尽量使用resultMap。

posted @   岁月淡忘了谁  阅读(868)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示