ibatis基本配置

 

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)

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值