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. 利用用python构建 个性化签名

    from tkinter import * from tkinter import messagebox,ttk from PIL import ImageTk import requests imp ...

  2. RAC4——架构和变化

    1.RAC的架构 2.由单实例变RAC的变化   1.SGA的变化: 和传统的单实例相比,RAC 实例中SGA最显著的变化时多了一个GRD(Global resource directory)部分. ...

  3. PHP接口开发加密技术实例原理与例子

    下面例子简单讲解PHP接口开发加密技术:如app要请求用户列表,api是“index.php?module=user&action=list”app生成token = md5sum (‘use ...

  4. 捕获长时间不提交的SQL语句

    /* Formatted on 2014/5/19 17:16:16 (QP5 v5.240.12305.39476) */ SELECT s.sid, s.serial#, ss.sql_text ...

  5. github for windows 使用

    先在github上申请账号,已有略过. 下载github for windows安装,可以提前安装.NET FRAMEWORK 4.0,否则它会在线下载安装.NET 4. 安装后登录账号,不要急着CL ...

  6. -Java-Runoob-高级教程-实例-数组:09. Java 实例 – 数组扩容

    ylbtech-Java-Runoob-高级教程-实例-数组:09. Java 实例 – 数组扩容 1.返回顶部 1. Java 实例 - 数组扩容  Java 实例 以下实例演示了如何在数组初始化后 ...

  7. JavaScript-Tool:Moment.js

    ylbtech-JavaScript-Tool:Moment.js Parse, validate, manipulate, and display dates and times in JavaSc ...

  8. 杂项:IIS

    ylbtech-杂项:IIS IIS是Internet Information Services的缩写,意为互联网信息服务,是由微软公司提供的基于运行Microsoft Windows的互联网基本服务 ...

  9. [UE4]把枪抽象为一个类

  10. Hibernate JavaBean.hbm.xml配置

    主键生成策略: hibernate中必须设置主键 <generator> 由数据库维护: identity:用于自动生成主键方式(没有自增主键的数据库不使用eg:oracle) seque ...