remapResults="true" ibatis 中每次查询出来的数据列重新映射,
xml文件中如果每次查询出来的数据的列数不一样则用此属性
<sql id="getList_body">
SELECT id, school , beginTime, endTime,
ROW_NUMBER() Over(ORDER BY id DESC) AS rowNum
FROM info
<dynamic prepend="WHERE">
<isNotNull prepend="AND" property="id"> id=#id# </isNotNull>
<isNotNull prepend="AND" property="school"> school=#school# </isNotNull>
<isNotNull prepend="AND" property="beginTime"> beginTime=#beginTime# </isNotNull>
<isNotNull prepend="AND" property="endTime"> endTime=#endTime# </isNotNull>
</dynamic>
</sql>
<select id="getListCount" resultClass="int">
SELECT COUNT(*) FROM (
<include refid="getList_body" />
) AS myTable
</select>
<select id="getList" parameterClass="com.Info" resultClass="com.Info">
SELECT * FROM (
<include refid="getList_body" />
) AS myTable WHERE rowNum between #rowNumStart# and #rowNumEnd#
</select>
---------插入
<insert id="insertInfo" parameterClass="com.Info">
INSERT INTO info (
<dynamic prepend=" ">
<isNotNull prepend="," property="school"> school </isNotNull>
<isNotNull prepend="," property="beginTime"> beginTime </isNotNull>
<isNotNull prepend="," property="endTime"> endTime </isNotNull>
</dynamic>
)
VALUES (
<!--prepend后面要有空格否则会出现多余逗号错误-->
<dynamic prepend=" ">
<isNotNull prepend="," property="school"> #school# </isNotNull>
<isNotNull prepend="," property="beginTime"> #beginTime# </isNotNull>
<isNotNull prepend="," property="endTime"> #endTime# </isNotNull>
</dynamic>
)
</insert>
<update id="info" parameterClass="com.Info">
UPDATE info
<dynamic prepend="SET">
<isNotNull prepend="," property="school"> school=#school:VARCHAR# </isNotNull>
<isNotNull prepend="," property="beginTime"> beginTime=#beginTime# </isNotNull>
<isNotNull prepend="," property="endTime"> endTime=#endTime# </isNotNull>
</dynamic>
<dynamic prepend="WHERE">
<isNotNull prepend="AND" property="id"> id=#id# </isNotNull>
</dynamic>
</update>
<select id="getInfo" parameterClass="com.Info" resultClass="com.Info">
SELECT * FROM info
<dynamic prepend="WHERE">
<isNotNull prepend="AND" property="id"> id=id </isNotNull>
<isNotNull prepend="AND" property="school"> school=#school# </isNotNull>
<isNotNull prepend="AND" property="beginTime"> beginTime=#beginTime# </isNotNull>
<isNotNull prepend="AND" property="endTime"> endTime=#endTime# </isNotNull>
</dynamic>
</select>
<parameterMap id="paramVal_sw" class="java.util.HashMap" >
<parameter mode="IN" property="course" jdbcType="VARCHAR" javaType="java.lang.String" />
<parameter mode="IN" property="id" jdbcType="VARCHAR" javaType="java.lang.String" />
<parameter mode="IN" property="user" jdbcType="VARCHAR" javaType="java.lang.String" />
<parameter mode="OUT" property="exeRtn" jdbcType="INTEGER" javaType="java.lang.Integer" />
</parameterMap>
<procedure id="insertCourse" parameterMap="paramVal_sw" resultClass="java.lang.Integer">
<![CDATA[{call proc_sc_getDetail(?,?,?)}]]>
</procedure>
如果传入的参数是整数 则转换一下 cast ($value$ as int)