分享

myBatis注解sql书写注意

 昵称70680357 2020-07-02

(1)在使用<where></where>,<if></if>等标签符号时一定要加<script></script>标签,其他情况可加可不加。
(2)里面牵涉的大于、小于、大于等于、小于等于符号要分别使用>、<、>=、<=表示否则会出错。
(3)换行结尾可用逗号或者加号

语言义视竭脯娩 主方法交勿钢梆科
48bHo 饺糊褐账多yh8QM
E68ZJ 直播怎么开
4GOjO qtvkMW2397
 @Insert({
            "<script>",
            "insert into phone (",
            "id," ,
            "phone," ,
            "phone_type, " ,
            "insert_time," ,
            "insert_user ) (" ,
            "<foreach collection='phoneInfos' item='phone' index='index' separator='union all'>",
            "   (select #{phone.id,jdbcType=VARCHAR},  " ,
            "  #{phone.phone,jdbcType=VARCHAR},  " ,
            "  #{phone.phone_type,jdbcType=VARCHAR},  " ,
            "  to_date(#{phone.insert_time,jdbcType=VARCHAR},'yyyy-mm-dd hh24:mi:ss'),  " ,
            "  #{phone.insert_user,jdbcType=VARCHAR} from dual)" ,
            "</foreach> )",
            "</script>"
    })
    int betchInsertPhone(@Param("phoneInfos")List<PhoneInfo> phoneInfos);
	
    @Select(" <script> " +
            " select count(*) from phone t " +
            " <where>"+
            " <if test='phone !=null and phone!=\"\"'>" +
            " and t.phone like '%${phone}%'" +
            " </if> " +
            " <if test='startDate !=null and startDate!=\"\"'> " +
            " and t.insert_time >= to_date('${startDate}','yyyy-mm-dd hh24:mi:ss') " +
            " </if> " +
            " <if test='endDate !=null and endDate!=\"\"'> " +
            " and t.insert_time <= to_date('${endDate}','yyyy-mm-dd hh24:mi:ss') " +
            " </if>" +
            " </where>" +
             " </script>")
    int countPhoneManager(@Param("startDate") String startDate,@Param("endDate") String endDate,@Param("ph

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约