zoukankan      html  css  js  c++  java
  • 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>


  • 相关阅读:
    springboot/springcloud 启动速度慢 卡死问题
    数据分析路线
    java杂
    贪吃蛇
    设计模式的七大原则
    Java--GUI编程(三)总结AWT/Swing
    时间复杂度
    Java--GUI编程(二)简易加法计算器
    Java--GUI编程(一)
    Java--this与super区别
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/2993462.html
Copyright © 2011-2022 走看看