mapper学习

1.插入后select是干啥呢?

/**
     * Insert server crash alert
     * <p>This method will ensure that there is at most one unsent alert which has the same content in the database.
     */
    void insertAlertWhenServerCrash(@Param("alert") Alert alert);
 <insert id="insertAlertWhenServerCrash">
        insert into t_ds_alert(title, content, alert_status, log, alertgroup_id, create_time, update_time)
        SELECT #{alert.title}, #{alert.content}, #{alert.alertStatus.code}, #{alert.log}, #{alert.alertGroupId},
               #{alert.createTime}, #{alert.updateTime}
        from t_ds_alert
        where content = #{alert.content} and alert_status = #{alert.alertStatus.code}
        having count(*) = 0
    </insert>

2.where 1=1是干啥呢?

 List<AlertPluginInstance> queryAllAlertPluginInstanceList();
    <select id="queryAllAlertPluginInstanceList"
            resultType="org.apache.dolphinscheduler.dao.entity.AlertPluginInstance">
        select *
        from t_ds_alert_plugin_instance
        where 1 = 1
    </select>

3.foreach是干啥呢?

   List<AlertPluginInstance> queryByIds(@Param("ids") List<Integer> ids);
    <select id="queryByIds" resultType="org.apache.dolphinscheduler.dao.entity.AlertPluginInstance">
        select *
        from t_ds_alert_plugin_instance
        where id in
        <foreach item="item" index="index" collection="ids"
                 open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

4.if这个怎么用?

IPage<AlertPluginInstance> queryByInstanceNamePage(Page page, @Param("instanceName") String instanceName);
    <select id="queryByInstanceNamePage" resultType="org.apache.dolphinscheduler.dao.entity.AlertPluginInstance">
        select
        *
        from t_ds_alert_plugin_instance
        where 1 = 1
        <if test="instanceName != null and instanceName != ''">
            and instance_name like concat('%', #{instanceName}, '%')
        </if>
    </select>

5.这个select 1是啥意思?

Boolean existInstanceName(@Param("instanceName") String instanceName);
    <select id="existInstanceName" resultType="java.lang.Boolean">
        select 1
        from t_ds_alert_plugin_instance
        where instance_name = #{instanceName} limit 1
    </select>

6.这个比较复杂

    List<CommandCount> countCommandState(
            @Param("userId") int userId,
            @Param("startTime") Date startTime,
            @Param("endTime") Date endTime,
            @Param("projectCodeArray") Long[] projectCodeArray);
    <select id="countCommandState" resultType="org.apache.dolphinscheduler.dao.entity.CommandCount">
        select cmd.command_type as command_type, count(1) as count
        from t_ds_command cmd, t_ds_process_definition process
        where cmd.process_definition_code = process.code
        <if test="projectCodeArray != null and projectCodeArray.length != 0">
            and process.project_code in
            <foreach collection="projectCodeArray" index="index" item="i" open="(" close=")" separator=",">
                #{i}
            </foreach>
        </if>
        <if test="startTime != null and endTime != null">
            and cmd.start_time <![CDATA[ >= ]]> #{startTime} and cmd.update_time <![CDATA[ <= ]]> #{endTime}
        </if>
        group by cmd.command_type
    </select>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值