Mybatis中like搭配concat的写法详解
更新时间:2022年01月21日 09:53:10 作者:天真.。
这篇文章主要介绍了Mybatis中like搭配concat的写法详解,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
Mybatis like搭配concat写法
在Mybatis中的写法
<!--concat Mysql和 Oracle区别 ,不存在sql注入-->
<select id="findUserByLikeName3" parameterType="java.lang.String" resultMap="user">
select * from t_user where name like concat('%',#{name,jdbcType=VARCHAR},'%')
</select>Mybatis concat()函数模糊查询
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 != ''"><!-- 开始时间检索 -->
and date_format(login_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
and date_format(login_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
</if>
</where>
</select>以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
mybatis-plus分页如何接收前端参数limit和page
这篇文章主要介绍了mybatis-plus分页如何接收前端参数limit和page,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2022-01-01
SpringBoot同时集成Mybatis和Mybatis-plus框架
在实际开发中,项目里面一般都是Mybatis和Mybatis-Plus公用,但是公用有版本不兼容的问题,本文主要介绍了Spring Boot项目中同时集成Mybatis和Mybatis-plus,具有一档的参考价值,感兴趣的可以了解一下2024-12-12
关于java.io.EOFException产生的原因以及解决方案
文章总结:EOFException异常通常发生在尝试从空的ObjectInputStream对象中读取数据时,解决方法是在finally语句中添加判断,确保objectInputStream不为空后再进行关闭操作,在处理1.txt文件为空的情况时,捕获EOFException可以避免程序终止,并且不会抛出空指针异常2025-01-01


最新评论