菜单开关

周梦康 发表于 2018-05-04 1669 次浏览 标签 : Mybatis
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.aliyun.inc.compass.mapper.TargetMapper" >
    <resultMap id="BaseResultMap" type="com.aliyun.inc.compass.domain.TargetDO" >
        <!--
          WARNING - @mbg.generated
        -->
        <id column="id" property="id" jdbcType="INTEGER" />
        <result column="biz_line" property="bizLine" jdbcType="TINYINT" />
        <result column="category" property="category" jdbcType="TINYINT" />
        <result column="status" property="status" jdbcType="TINYINT" />
        <result column="time_cycle" property="timeCycle" jdbcType="TINYINT" />
        <result column="title" property="title" jdbcType="VARCHAR" />
        <result column="description" property="description" jdbcType="VARCHAR" />
        <result column="compute_rule" property="computeRule" jdbcType="VARCHAR" />
        <result column="data_from" property="dataFrom" jdbcType="VARCHAR" />
        <result column="biz_user" property="bizUser" jdbcType="VARCHAR" />
        <result column="bi_user" property="biUser" jdbcType="VARCHAR" />
        <result column="center_user" property="centerUser" jdbcType="VARCHAR" />
        <result column="dev_user" property="devUser" jdbcType="VARCHAR" />
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
        <result column="operate_uid" property="operateUid" jdbcType="INTEGER" />
        <result column="is_del" property="isDel" jdbcType="TINYINT" />
    </resultMap>

    <!--多条件筛选-->
    <select id="listAllByPage" resultMap="BaseResultMap">
        SELECT * FROM target
        <where>
            <if test="targetDO.bizLine != 0">
                biz_line = #{targetDO.bizLine}
            </if>
            <if test="targetDO.category != 0">
                AND category = #{targetDO.category}
            </if>
            <if test="targetDO.status != 0">
                AND status = #{targetDO.status}
            </if>
            <if test="targetDO.timeCycle != 0">
                AND time_cycle = #{targetDO.timeCycle}
            </if>
            <if test="targetDO.isDel != null">
                AND is_del = #{targetDO.isDel}
            </if>
        </where>
        ORDER BY id desc limit #{offset}, #{limit}
    </select>

    <select id="countAll" resultType="java.lang.Integer">
        SELECT count(*) FROM target
        <where>
            <if test="targetDO.bizLine != 0">
                biz_line = #{targetDO.bizLine}
            </if>
            <if test="targetDO.category != 0">
                AND category = #{targetDO.category}
            </if>
            <if test="targetDO.status != 0">
                AND status = #{targetDO.status}
            </if>
            <if test="targetDO.timeCycle != 0">
                AND time_cycle = #{targetDO.timeCycle}
            </if>
            <if test="targetDO.isDel != null">
                AND is_del = #{targetDO.isDel}
            </if>
        </where>
    </select>

    <update id="updateOne">
        UPDATE target
        <trim prefix="set" suffixOverrides=",">
            <if test="targetDO.bizLine != null">
                biz_line = #{targetDO.bizLine},
            </if>
            <if test="targetDO.category != null">
                category = #{targetDO.category},
            </if>
            <if test="targetDO.status != null">
                status = #{targetDO.status},
            </if>
            <if test="targetDO.timeCycle != null">
                time_cycle = #{targetDO.timeCycle},
            </if>
            <if test="targetDO.isDel != null">
                is_del = #{targetDO.isDel},
            </if>
            <if test="targetDO.title != null">
                title = #{targetDO.title},
            </if>
            <if test="targetDO.description != null">
                description = #{targetDO.description},
            </if>
            <if test="targetDO.computeRule != null">
                compute_rule = #{targetDO.computeRule},
            </if>
            <if test="targetDO.dataFrom != null">
                data_from = #{targetDO.dataFrom},
            </if>
            <if test="targetDO.bizUser != null">
                biz_user = #{targetDO.bizUser},
            </if>
            <if test="targetDO.biUser != null">
                bi_user = #{targetDO.biUser},
            </if>
            <if test="targetDO.centerUser != null">
                center_user = #{targetDO.centerUser},
            </if>
            <if test="targetDO.devUser != null">
                dev_user = #{targetDO.devUser},
            </if>
            <if test="targetDO.devUser != null">
                dev_user = #{targetDO.devUser},
            </if>
            <if test="targetDO.updateTime != null">
                update_time = #{targetDO.updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="targetDO.operateUid != null">
                operate_uid = #{targetDO.operateUid},
            </if>
        </trim>
        WHERE id=#{targetDO.id}
    </update>
    
    <select id="searchCount" resultType="java.lang.Integer">
        SELECT count(*) FROM target
        <where>
            <if test="targetDO.title != null">
                title like CONCAT('%',#{targetDO.title},'%')
            </if>
            <if test="targetDO.description != null">
                AND description like CONCAT('%',#{targetDO.description},'%')
            </if>
            <if test="targetDO.bizUser != null">
                AND bizUser like CONCAT('%',#{targetDO.bizUser},'%')
            </if>
        </where>
    </select>
</mapper>

知识点

  • 动态查询
  • 动态更新
  • Date 类型字段如何更新
  • 模糊搜索

评论列表