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>


  • 相关阅读:
    「BJOI2018」治疗之雨
    「NOIP2016」换教室
    「HNOI2015」亚瑟王
    2019/9/15 四校联训
    【AtCoder】 ARC 097
    【AtCoder】 ARC 098
    【AtCoder】 ARC 099
    【AtCoder】 ARC 100
    React:JS中的this和箭头函数
    React:styled-components
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/2993462.html
Copyright © 2011-2022 走看看