美文网首页Java技术研究
Springboot+myBatis模糊查询--直接上代码

Springboot+myBatis模糊查询--直接上代码

作者: 晨曦诗雨 | 来源:发表于2018-11-29 11:22 被阅读1次

    查询

     <select id="queryParkNoPage" resultMap="ParkNoResultMap" parameterType="java.util.HashMap">
            SELECT *  FROM park_no n left JOIN  org o ON n.orgId=o.id
            <where>
                <if test="orgCode != null and orgCode !=''">
                     o.orgCode like  CONCAT(#{orgCode},'%')
                </if>
                <if test="parkName != null and parkName !=''">
                    and  n.parkName like  CONCAT('%',#{parkName},'%')
                </if>
                <if test="startDate != null">
                    <![CDATA[  and DATE_FORMAT(n.createDate, '%Y-%m-%d %H:%T:%s') >=  DATE_FORMAT(#{startDate} , '%Y-%m-%d %H:%T:%s')    ]]>
                </if>
                <if test="endDate != null">
                    <![CDATA[  and DATE_FORMAT(n.createDate, '%Y-%m-%d %H:%T:%s') <=  DATE_FORMAT(#{endDate} , '%Y-%m-%d %H:%T:%s')    ]]>
                </if>
                <if test="parkCodes != null  and parkCodes.size > 0 ">
                    and n.parkCode in
                    <foreach collection="parkCodes" item="code" separator=","  open="(" close=")">
                        #{code}
                    </foreach>
                </if>
            </where>
        </select>
    

    时间的模糊查

     <select id="findFirstByCreateDateBetweenAndParkNo_ParkCodeOrderByCreateDate" resultMap="ParkSurplusResultMap">
           SELECT *  FROM  park_surplus p
           LEFT JOIN  park_no n ON p.parkId=n.id
           LEFT JOIN  org o ON n.orgId=o.id
           WHERE   n.parkCode like  CONCAT(#{parkCode},'%')
           AND  p.createDate BETWEEN  #{start} AND  #{end}
           ORDER BY n.parkCode DESC
        </select>
    

    排序的查询

     <select id="findByOrg_OrgCodeOrderByParkCodeDesc" resultMap="ParkNoResultMap">
             SELECT
               *
              FROM park_no n left JOIN  org o ON n.orgId=o.id  WHERE  o.orgCode=#{orgCode} ORDER BY n.parkCode DESC
        </select>
    

    插入批量

    <insert id="saveAudits" parameterType="java.util.List" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
            INSERT INTO
            audit
            (level,content,confirm,orgCode,createDate)
            values
            <foreach collection="list" item="p" index="index"  separator=",">
                (#{p.level},#{p.content},#{p.confirm},#{p.orgCode},#{p.createDate})
            </foreach>
        </insert>
    

    单个插入

    <insert id="saveAudit" parameterType="com.dwtc.park.web.modules.audit.entity.Audit" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
           INSERT INTO
             audit
            (level,content,confirm,orgCode,createDate)
            VALUES
            (#{level},#{content},#{confirm},#{orgCode},#{createDate})
        </insert>
    

    删除

    <delete id="deleteBySessionId" parameterType="java.lang.String">
            DELETE  FROM  login_user WHERE  sessionId=#{param1}
        </delete>
    

    批量删除

    <delete id="deleteUploadMessages" parameterType="java.lang.Long">
            DELETE  FROM  upload_message WHERE
            id IN
            <foreach collection="array" item="item" index="index"  separator=","  open="(" close=")">
                #{item}
            </foreach>
        </delete>
    

    更新

     <update id="updateOrg" parameterType="com.dwtc.park.web.modules.org.entity.Org">
            UPDATE  org
            <set>
                <if test="parentCode != null and parentCode != ''">parentCode=#{parentCode},</if>
                <if test="orgCode != null and orgCode != ''">orgCode=#{orgCode},</if>
                <if test="orgName != null and orgName != ''">orgName=#{orgName},</if>
                <if test="areaCode != null and areaCode != ''">areaCode=#{areaCode},</if>
                <if test="createDate != null ">createDate=#{createDate},</if>
            </set>
            WHERE id=#{id}
        </update>
    
    <insert id="updateSession" parameterType="com.dwtc.park.plugin.rabbitmq.entity.ParkSession" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
           update park_session SET messagekey=#{messagekey},parkKey=#{parkKey},parkCode=#{parkCode},status=#{status} where messagekey=#{messagekey}
        </insert>
    

    相关文章

      网友评论

        本文标题:Springboot+myBatis模糊查询--直接上代码

        本文链接:https://www.haomeiwen.com/subject/eapxcqtx.html