本文概览:介绍常常用的返回类型和参数类型。
1 参数类型
1.1 参数类型为List类型时
根据List中元素类型可以分为两种类型:
1 类型1 List中类型是一个基本类型,此时指接使用#item来去成员的值
1 2 3 4 5 6 7 8 9 10 11 12 13 |
select id="getCmsConstantById" parameterType="java.util.List" resultType="com.qunar.hotel.crm.model.CmsConstant"> SELECT <include refid="Base_Column_List" /> FROM cms_constant WHERE id in <foreach item="item" index="index" collection="idList" open="(" separator="," close=")"> #{item} </foreach> AND STATUS = '1' </select> |
2.类型2 List中类型是一个对象类型#item.version
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<insert id="batchInsert" parameterType="java.util.List"> insert into hour_room( version, pkg_serial, attribute, create_time ) values <foreach collection="hourRoomEntities" item="item" index="index" separator=","> ( #{item.version}, #{item.pkgSerial}, #{item.attribute}, now() ) </foreach> </insert> |
1.2 参数Map或者对象类型
参考如下
2 返回类型
2.1 使用requestType
返回值为list<Stirng>时,resultType需要设置为String
1 2 3 4 5 6 7 8 9 |
<select id="queryFailedCluster" parameterType="string" resultType="String"> select serial_number from crm_entertainment_cluster_history where state = 0 order by operate_time desc limit #{n} </select> |
2.2 使用 resultMap
1. resultMap的设置
1 2 3 4 5 6 7 |
<resultMap id="QsightSyncInfoLogEntity" type="com.qunar.hotel.crm.model.entertainment.QsightSyncInfoLogEntity"> <result column="id" property="id"/> <result column="qsight_id" property="qsightId"/> <result column="attribute" property="attribute"/> <result column="md5" property="md5"/> <result column="operate_time" property="operateTime"/> </resultMap> |
2. sletect语句
1 2 3 4 5 6 7 8 9 |
<select id="queryLog" parameterType="int" resultMap="QsightSyncInfoLogEntity"> select <include refid="QsightSyncInfoLogFields"/> from qsight_sync_info_log where qsight_id = #{qsightId} order by operate_time desc limit 1 </select> |
(全文完)