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>


  • 相关阅读:
    jsp第八次作业
    jsp第七次作业
    jsp第六次作业
    jsp第五次作业
    jsp第二次作业
    软件测试第一次作业
    第一本书的学习笔记
    第零次作业
    software engineering task0
    自己创建的mysql用户无法使用密码登录,直接用用户名就可以登录的问题
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/2993462.html
Copyright © 2011-2022 走看看