Mybatis中l(wèi)ike搭配concat的寫法詳解
更新時(shí)間:2022年01月21日 09:53:10 作者:天真.。
這篇文章主要介紹了Mybatis中l(wèi)ike搭配concat的寫法詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
Mybatis like搭配concat寫法
在Mybatis中的寫法
?<!--concat Mysql和 Oracle區(qū)別 ,不存在sql注入-->
? <select id="findUserByLikeName3" parameterType="java.lang.String" resultMap="user">
? ? ? select * from t_user where name like concat('%',#{name,jdbcType=VARCHAR},'%')
? </select>Mybatis concat()函數(shù)模糊查詢
mysql 的 like,建議 like concat() 組合,可以防止sql注入
?? ?<select id="selectLogininforList" parameterType="SysLogininfor" resultMap="SysLogininforResult">
?? ??? ?select info_id,login_name,ipaddr,login_location,browser,os,status,msg,login_time from sys_logininfor
?? ??? ?<where>
?? ??? ??? ?<if test="ipaddr != null and ipaddr != ''">
?? ??? ??? ??? ?AND ipaddr like concat('%', #{ipaddr}, '%')
?? ??? ??? ?</if>
?? ??? ??? ?<if test="status != null and status != ''">
?? ??? ??? ??? ?AND status = #{status}
?? ??? ??? ?</if>
?? ??? ??? ?<if test="loginName != null and loginName != ''">
?? ??? ??? ??? ?AND login_name like concat('%', #{loginName}, '%')
?? ??? ??? ?</if>
?? ??? ??? ?<if test="params.beginTime != null and params.beginTime != ''"><!-- 開(kāi)始時(shí)間檢索 -->
?? ??? ??? ??? ?and date_format(login_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
?? ??? ??? ?</if>
?? ??? ??? ?<if test="params.endTime != null and params.endTime != ''"><!-- 結(jié)束時(shí)間檢索 -->
?? ??? ??? ??? ?and date_format(login_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
?? ??? ??? ?</if>
?? ??? ?</where>
?? ?</select>以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
mybatis-plus分頁(yè)如何接收前端參數(shù)limit和page
這篇文章主要介紹了mybatis-plus分頁(yè)如何接收前端參數(shù)limit和page,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-01-01
SpringBoot同時(shí)集成Mybatis和Mybatis-plus框架
在實(shí)際開(kāi)發(fā)中,項(xiàng)目里面一般都是Mybatis和Mybatis-Plus公用,但是公用有版本不兼容的問(wèn)題,本文主要介紹了Spring Boot項(xiàng)目中同時(shí)集成Mybatis和Mybatis-plus,具有一檔的參考價(jià)值,感興趣的可以了解一下2024-12-12
Spring Cloud實(shí)戰(zhàn)技巧之使用隨機(jī)端口
這篇文章主要給大家介紹了關(guān)于Spring Cloud實(shí)戰(zhàn)技巧之使用隨機(jī)端口的相關(guān)資料,文中介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面跟著小編一起來(lái)學(xué)習(xí)學(xué)習(xí)吧。2017-06-06
關(guān)于java.io.EOFException產(chǎn)生的原因以及解決方案
文章總結(jié):EOFException異常通常發(fā)生在嘗試從空的ObjectInputStream對(duì)象中讀取數(shù)據(jù)時(shí),解決方法是在finally語(yǔ)句中添加判斷,確保objectInputStream不為空后再進(jìn)行關(guān)閉操作,在處理1.txt文件為空的情況時(shí),捕獲EOFException可以避免程序終止,并且不會(huì)拋出空指針異常2025-01-01
Java讀文件修改默認(rèn)換行符的實(shí)現(xiàn)
這篇文章主要介紹了Java讀文件修改默認(rèn)換行符的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-12-12
java并發(fā)容器ConcurrentHashMap深入分析
這篇文章主要為大家介紹了java并發(fā)容器ConcurrentHashMap使用示例及深入分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-05-05

