mapper @Select()注解开发,使用模板 if 和循环

if

    @Select({"<script>",
            "SELECT   " +
                    "   mu.id userId,   " +
                    "   eui.id userInfoId,   " +
                    "   mu.user_name userName,   " +
                    "   com.company_id AS comId,   " +
                    "   com.company_name comName,   " +
                    "   eui.talent_type talentType,   " +
                    "   eui.self_introduction selfIntroduction,   " +
                    "   eui.working_years workingYears,   " +
                    "   eui.education education,   " +
                    "   mu.icon_url iconUrl    " +
                    " FROM   " +
                    "   mky_user mu,   " +
                    "   em_company c,   " +
                    "   em_company_record com,   " +
                    "   em_user_info eui,   " +
                    "   em_aptitude_maintain_approve ea   " +
                    " WHERE 1=1 ",
            " <when test=‘searchStr!=null‘> ",
            "   AND ( mu.user_name LIKE #{searchStr} OR com.company_name LIKE  #{searchStr} ) ",
            " </when> ",
            " <when test=‘firstId!=null‘> ",
            " AND ea.first_id = #{firstId} ",
            " </when> ",

            " <when test=‘secondId!=null‘> ",
            " AND ea.second_id = #{secondId} ",
            " </when> ",

            " <when test=‘threeId!=null‘> ",
            " AND ea.three_id = #{threeId} ",
            " </when> ",
            " <when test=‘startDate!=null‘> ",
            "  AND ea.end_date &gt; #{startDate}  ",
            " </when> ",
            " <when test=‘endDate!=null‘> ",
            "  AND ea.end_date  &lt; #{endDate}  ",
            " </when> ",
            "    AND c.id = com.company_id    " +
                    "   AND mu.com_id = c.id    " +
                    "   AND mu.id = eui.user_id    " +
                    "   AND eui.page_display_flag = 1    " +
                    "   AND ea.user_info_id = eui.id  " +
                    "   AND ea.end_date &gt; DATE_FORMAT( now( ), ‘%Y-%m-%d‘ ) " +

                    "   AND mu.del_flag = 0    " +
                    "   AND ea.del_flag = 0    " +
                    "   AND eui.del_flag = 0    " +
                    "   AND c.del_flag = 0    " +
                    "   AND com.del_flag = 0   " +

                    "  GROUP BY   eui.id   " +
                    "  ORDER BY   " +
                    "   eui.update_date DESC  " +

                    " </script> "})
    List<TalentsResultVo> selectAllTalentsByParams(@Param("firstId") String firstId, @Param("secondId") String secondId, @Param("threeId") String threeId, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("searchStr") String searchStr);

循环

    @Select({
            " <script> ",
            " select ",
            " id ,stream_id  ‘streamId‘ , project_id  ‘projectId‘ ,push_stream_addr ‘pushStreamAddr‘ , rtmp_play_addr  ‘rtmpPlayAddr‘ , flv_play_addr ‘flvPlayAddr‘ , hls_play_addr ‘hlsPlayAddr‘ ,  monitor_state  ‘monitorState‘, monitor_name  ‘monitorName‘ , note, state_reason  ‘stateReason‘ , ip_addr ‘ipAddr‘  ",
            " from bi_real_time_monitoring ",
            "  where  project_id in ",
            " <foreach collection=‘projectIds‘ item=‘id‘ open=‘(‘ separator=‘,‘ close=‘)‘> ",
            " #{id} ",
            " </foreach> ",
            " and delFlag =0  and monitor_state != 2 ",
            " </script> "
    })
 
    List<BiRealTimeMonitoring> selectBiRealTimeMonitoringByProjectIds(@Param("projectIds") List<String> projectIds);

注意一个报错

注意一个报错

 

mapper @Select()注解开发,使用模板 if 和循环

上一篇:Android 项目优化(七):阿里巴巴Android开发手册整理总结


下一篇:call和apply