• Mybatis SQL转义字符与like 查询


    Mybatis Sql语句里一些特殊符号是必须转义的,否则无法正常运行,有些会在静态语法检查上IDE会提示,有些则只会在运行时抛出异常。需要转义的符号如下

       &lt;          < 
        &gt;          >  
        &lt;&gt;  <>
        &amp;      & 
        &apos;      '
        &quot;      "

    <sql id="getAllWhere">
    	
    		<if test="condition != null">
    			<if test="condition.type >0">
    				<!-- 歌手类别 -->
    				and g.type = #{condition.type}
    			</if>
    			<if test="condition.mediaName != null">
    				<!-- 歌名汉字 ,下面三种写法都可以--> 
    					and media_name like '%${condition.mediaName}%'
    <!-- 				and media_name like '%${condition.mediaName}%' -->
    <!-- 				and media_name like CONCAT(CONCAT('%',#{condition.mediaName}),'%') -->
    			</if>
    			<if test="condition.geQuLeng > 0">
    				<!-- 歌名字数,UTF-8一个汉字的长度为3 -->
    				<if test="condition.geQuLeng > 9"> and length(media_name) >= #{condition.geQuLeng}	</if>
    				<if test="condition.geQuLeng < 10"> and length(media_name) = #{condition.geQuLeng}	</if>
    			</if>
    			
    		</if>
    		<!-- 时间排序 -->
    		<if test="sort != null ">
    			<if test="order != null"> order by #{sort} #{order} </if>
    			<if test="order == null"> order by #{sort} desc </if>
    		</if>
    	</sql>


  • 相关阅读:
    bzoj1084
    bzoj1088 [SCOI2005]扫雷
    [LUOGU] 1892 团伙
    [普及组] 2017 成绩
    [LUOGU] P2661 信息传递
    [LUOGU] P1339 [USACO09OCT]热浪Heat Wave
    [LUOGU] P1828 香甜的黄油 Sweet Butter
    [模板] 单源最短路径
    [LUOGU] 1717 钓鱼
    [UVA] 704 Colour Hash
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/2993462.html
Copyright © 2020-2023  润新知