Ibatis中,两个表关联查询,返回类型怎么写
时间:2011-11-15
来源:互联网
语句如下:
XML code
返回类型应该写什么,resultMap和resultClass有什么区别,什么时候用哪个怎么判断?
在<resultMap id="TbMmsTopicLibMap" class="com.cloudsoaring.mms.entity.TbMmsTopicLibEntity">这里应该怎么配置,对这个没用过,很模糊,
XML code
<!-- 从议题库表,汇报单位表,会议信息表查询--> <select id="searchTopicInfoByTopicId" parameterClass="TbMmsTopicLib" resultMap="TbMmsTopicLibMap"> SELECT T.TOPIC_ID ,T.TOPIC_TITLE <!-- 议题名称--> ,R.UNIT_NAME <!-- 汇报单位--> ,T.APPROVAL_LEADER <!-- 审签领导--> ,T.APPROVAL_DATE <!-- 审签日期--> ,M.MEETING_NUM <!-- 第几届会议:会议名称--> ,M.MEETING_DATE <!-- 会议时间--> FROM TB_MMS_TOPIC_LIB T LEFT JOIN TB_MMS_REPORT_UNIT R ON T.TOPIC_ID = R.TOPIC_ID RIGHT JOIN TB_MMS_MEETINGS M ON T.MEETING_ID = M.MEETING_ID WHERE T.TOPIC_ID = #topicId# </select>
返回类型应该写什么,resultMap和resultClass有什么区别,什么时候用哪个怎么判断?
在<resultMap id="TbMmsTopicLibMap" class="com.cloudsoaring.mms.entity.TbMmsTopicLibEntity">这里应该怎么配置,对这个没用过,很模糊,
作者: yangdonghhm 发布时间: 2011-11-15
引用
1. 返回类型应该写什么,resultMap和resultClass有什么区别,什么时候用哪个怎么判断?
回答:
resultMap属于直接映射,可以把结果集中的数据库字段与实体类中的属性一一对应,这样通过select语句得到的结果就会准确的对上号
resultclass属于隐身映射,虽然你指定resultclass=“”,具体某一个类,但是select语句得到的结果是一条实力记录,但如果数据库字段与类的属性名字不一致,这个时候就会出现映射错误,有一种方式可以解决就是在写select语句时,给每个字段用as运算符取名字与属性一样:例如:select realname as name...其中realname是字段列名,name是属性字段名
resultmap比resultclass性能要高。尽量使用resultmap
2. 在<resultMap id="TbMmsTopicLibMap" class="com.cloudsoaring.mms.entity.TbMmsTopicLibEntity">这里应该怎么配置
看实例中红字部分:
<!-- 为AmUser类设置一个别名 -->
<typeAlias alias="amUser"
type="com.ringid.inner.service.database.pojo.AmUsers" />
<!-- 查询返回对象 -->
<resultMap id="relAmUser" class="amUser">
<result property="personId" column="PERSON_ID" />
<result property="localeCode" column="LOCALE_CODE" />
<result property="status" column="STATUS" nullValue="0"/>
<result property="accountExpDate" column="ACCOUNT_EXP_DATE" />
<result property="selfRegistrationId" column="SELF_REGISTRATION_ID" />
<result property="dn" column="DN" />
</resultMap>
<!-- 高级查询am用户对象信息 -->
<select id="highFindAmUserObjects" resultMap="relAmUser"
parameterClass="userfilter">
select * from am_users
<dynamic prepend="where">
<isNotEqual prepend="AND" property="personId" compareValue="-1"> person_id = #personId#
</isNotEqual>
<isNotNull prepend="AND" property="usrLogin"> usr_login = #usrLogin#
</isNotNull>
<isNotEqual prepend="AND" property="status" compareValue="-1"> status = #status#
</isNotEqual>
<isNotNull prepend="AND" property="email"> email = #email#
</isNotNull>
<isNotNull prepend="AND" property="personalMobile"> personal_mobile = #personalMobile#
</isNotNull>
</dynamic>
order by usr_login asc, person_id desc
</select>
1. 返回类型应该写什么,resultMap和resultClass有什么区别,什么时候用哪个怎么判断?
回答:
resultMap属于直接映射,可以把结果集中的数据库字段与实体类中的属性一一对应,这样通过select语句得到的结果就会准确的对上号
resultclass属于隐身映射,虽然你指定resultclass=“”,具体某一个类,但是select语句得到的结果是一条实力记录,但如果数据库字段与类的属性名字不一致,这个时候就会出现映射错误,有一种方式可以解决就是在写select语句时,给每个字段用as运算符取名字与属性一样:例如:select realname as name...其中realname是字段列名,name是属性字段名
resultmap比resultclass性能要高。尽量使用resultmap
2. 在<resultMap id="TbMmsTopicLibMap" class="com.cloudsoaring.mms.entity.TbMmsTopicLibEntity">这里应该怎么配置
看实例中红字部分:
<!-- 为AmUser类设置一个别名 -->
<typeAlias alias="amUser"
type="com.ringid.inner.service.database.pojo.AmUsers" />
<!-- 查询返回对象 -->
<resultMap id="relAmUser" class="amUser">
<result property="personId" column="PERSON_ID" />
<result property="localeCode" column="LOCALE_CODE" />
<result property="status" column="STATUS" nullValue="0"/>
<result property="accountExpDate" column="ACCOUNT_EXP_DATE" />
<result property="selfRegistrationId" column="SELF_REGISTRATION_ID" />
<result property="dn" column="DN" />
</resultMap>
<!-- 高级查询am用户对象信息 -->
<select id="highFindAmUserObjects" resultMap="relAmUser"
parameterClass="userfilter">
select * from am_users
<dynamic prepend="where">
<isNotEqual prepend="AND" property="personId" compareValue="-1"> person_id = #personId#
</isNotEqual>
<isNotNull prepend="AND" property="usrLogin"> usr_login = #usrLogin#
</isNotNull>
<isNotEqual prepend="AND" property="status" compareValue="-1"> status = #status#
</isNotEqual>
<isNotNull prepend="AND" property="email"> email = #email#
</isNotNull>
<isNotNull prepend="AND" property="personalMobile"> personal_mobile = #personalMobile#
</isNotNull>
</dynamic>
order by usr_login asc, person_id desc
</select>
作者: kouyiSC 发布时间: 2011-11-15
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28