mybatis查找数据

Posted 沙漠里的小鱼

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mybatis查找数据相关的知识,希望对你有一定的参考价值。

<insert id="insertActivity" parameterType="com.aspirecn.mcp.activity.entity.Activity" flushCache="true">
    <selectKey resultType="int" keyProperty="id" order="BEFORE">
        SELECT SEQ_T_ACTIVITY_ID.NEXTVAL FROM DUAL
    </selectKey>
    INSERT INTO T_ACTIVITY (
        ID,
        ACT_NAME,
        START_TIME,
        END_TIME,
        AREA_CODE,
        CREATOR,
        SERVICE_NUMBER,
        SYS_SERVICE_NUMBER,
        STATUS,
        AUDIT_STATUS,
        REMARKS,
        RESERVE,
        SMS_CATEGORY_ID,
        MMS_CATEGORY_ID
    )
    VALUES (
        #{id,jdbcType=NUMERIC},
        #{activityName},
        #{startTime},
        #{endTime},
        #{areaCode},
        #{creator},
        #{serviceNumber},
        #{sysServiceNumber},
         #{status},
        #{auditStatus},
        #{remarks,jdbcType=VARCHAR},
         #{reserve,jdbcType=VARCHAR},
        #{smsCategoryId},
        #{mmsCategoryId}
    )
</insert>
<select id="listActivity" resultMap="activityResult" parameterType="com.aspirecn.mcp.activity.entity.Activity">
<![CDATA[
    SELECT
        ID,
        ACT_NAME,
        START_TIME,
        END_TIME,
        AREA_CODE,
        CREATE_TIME,
        LAST_UPDATE_TIME,
        CREATOR,
        SERVICE_NUMBER,
        STATUS,
        AUDIT_STATUS,
        REMARKS,
        RESERVE,
        SMS_CATEGORY_ID,
        MMS_CATEGORY_ID
    FROM T_ACTIVITY
]]>
        <where>
            <if test="id!=null">
                ID = #{id}
            </if>
            <if test="activityName != null and activityName !=‘‘">
                AND ACT_NAME LIKE #{activityName}
            </if>
            <if test="status!=null">
                AND STATUS = #{status}
            </if>
            
            <if test="queryType != null and queryType == 1">
                AND AUDIT_STATUS IN (2,8,10)
            </if>
            <if test="auditStatus!=null">
                AND AUDIT_STATUS = #{auditStatus}
            </if>
            
            <if test="startTime!=null">
                AND START_TIME &gt;= #{startTime}
            </if>
            <if test="endTime!=null">
                AND END_TIME &lt;= #{endTime}
            </if>
            <if test="areaCode!=null">
                AND AREA_CODE = #{areaCode}
            </if>
        </where>
        ORDER BY ID DESC
</select>

 

以上是关于mybatis查找数据的主要内容,如果未能解决你的问题,请参考以下文章

mybatis学习(39):动态sql片段

SSM-MyBatis-05:Mybatis中别名,sql片段和模糊查询加getMapper

mybatis动态sql片段与分页,排序,传参的使用

MyBatis动态SQL标签用法

MyBatis查询mysql数据返回null

MYBATIS05_ifwherechoosewhentrimsetforEach标签sql片段