Ibatis/Mybatis模糊查询

根据网络内容整理

Ibatis中

  1. 使用$代替#。此种方法就是去掉了类型检查,使用字符串连接,不过可能会有sql注入风险

Sql代码 select * from table1 where name like '%$name$%'

  1. 使用连接符。不过不同的数据库中方式不同。

    mysql:  select  *  from table1 where name like concat('%', #name#, '%')
    oracle: select * from table1 where name like '%' || #name# || '%'
    sql server: select * from table1 where name like '%' + #name# + '%'

注意:在实际开发中,往往我们需要将模糊查询的空格去掉。为了防止将去除空格放到业务层去,因此建议如下写(oracle 中,其他数据库雷同):

Sql代码 select * from table1 where name like '%' || Trim(#name#) || '%'


MyBatis中

like "%"#{name}"%"   <!--推荐使用--> (psql中有问题)
like '%'||#{name}||'%'
like '%${name}%'
like CONCAT('%',#{name},'%')
sqlserver: like '%'+#{name}+'%'

Ibatis/Mybatis模糊查询的更多相关文章

  1. MyBatis模糊查询相关

    Mybatis模糊查询的实现不难,如下实例:在UserMapper.xml中根据用户名模糊查询用户: <!-- 模糊查询用户 --> <select id="findSom ...

  2. Mybatis 模糊查询 中文问题

    IDE编码:GBK ,换成UTF-8也不行! @Testpublic void testSearchStudents() {logger.info("查询学生(带条件)");Map ...

  3. MyBatis模糊查询不报错但查不出数据的一种解决方案

    今天在用MyBatis写一个模糊查询的时候,程序没有报错,但查不出来数据,随即做了一个测试,部分代码如下: @Test public void findByNameTest() throws IOEx ...

  4. MyBatis——模糊查询

    在mybatis中可以使用三种模糊查询的方式: <!-- 模糊查询 --> <select id="selectListByTitle" parameterTyp ...

  5. mybatis模糊查询防止SQL注入

    SQL注入,大家都不陌生,是一种常见的攻击方式.攻击者在界面的表单信息或URL上输入一些奇怪的SQL片段(例如“or ‘1’=’1’”这样的语句),有可能入侵参数检验不足的应用程序.所以,在我们的应用 ...

  6. Mybatis 模糊查询 like【笔记】Could not set parameters for mapping

    当使用mybatis 做模糊查询时如果这样写 会报 Could not set parameters for mapping: ParameterMapping{property='keywords' ...

  7. mybatis模糊查询(转载)

    原文地址:http://blog.csdn.net/luqin1988/article/details/7865643 模糊查询: 1. sql中字符串拼接 SELECT * FROM tableNa ...

  8. MyBatis 模糊查询的 4 种实现方式

    引言 MyBatis 有 4 种方式可以实现模糊查询. 员工信息表 ( tb_employee ) 如下: id name sex email birthday address 001 张一凡 男 z ...

  9. Mybatis模糊查询结果为空的解决方案

    写在前面 Mybatis使用模糊查询,查询结果为空的解决方案,我的代码是 select * from sp_user where 1=1 <if test="username!=nul ...

随机推荐

  1. netty SimpleChannelInboundHandler<Message>和ChannelInboundHandlerApter

    一个兄弟的测试体验:https://blog.csdn.net/linuu/article/details/51307060 比较官方:https://www.imooc.com/article/28 ...

  2. 合并Dev BPL教程

    一.准备工具 1.Devexpress vcl 14.2.2 下载地址http://download.csdn.net/user/rfjbco,共用个包,下载后解压,程序目录已带有DxAutoInst ...

  3. BASIC-22_蓝桥杯_FJ的字符串

    示例代码: #include <stdio.h>#define N 1000000 int main(void){ int n = 0 , i = 0; char arr[N] , tmp ...

  4. gem install redis报错解决

    在执行gem install redis时 提示:    gem install redis    ERROR:  Error installing redis:            redis r ...

  5. 修改phpMYadmin 链接其他数据库地址的方法

    找到phpmyadmin的文件 修改 config.inc.php 文件 框红的地方修改成你需要链接的数据库信息 重启环境,再次访问 phpmyadmin 地址即可

  6. java-appium-527手机浏览器、PC端程序、grid模式

    1.手机浏览器 2.window通用成语自动化 3.appium支持grid模式

  7. [UE4]头文件循环依赖C++

    有2个类:aaa和bbb. aaa.h已经#include了bbb.h,则bbb.h就不能#include aaa.h,但bbb.cpp可以#include aaa.h bbb.h已经#include ...

  8. 企业常用的RPC框架比较

    RPC框架比较     语言 协议 服务治理 社区 机构 Hessian 多语言 hessian(二进制) – 不活跃 Caucho Thrift 多语言 thrift – 活跃 Apache Fin ...

  9. 深入理解HTTP协议之POST方法——ajax实例

    作者:吴俊杰 性别:男 邮箱:sshroot@126.com 文章类型:原创 博客:http://www.cnblogs.com/voiphudong/ 一.说明http协议其实是一个相对比较简单的应 ...

  10. tf.matmul函数和tf.multiply函数

    tf.matmul(a,b,transpose_a=False,transpose_b=False, adjoint_a=False, adjoint_b=False, a_is_sparse=Fal ...