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. Oracle 表空间与数据文件

    -============================== --Oracle 表空间与数据文件 --============================== /* 一.概念 表空间:是一个或多 ...

  2. 前端可视化建模技术概览,包括:GoJS

    我推荐使用的: 库 网址 备注 GoJS https://gojs.net/latest/samples/flowchart.html 推荐使用 相关文章: 前端可视化建模技术概览:http://le ...

  3. Collection与Collections,Array与Arrays的区别

    Collection 和 Collections的区别 Collection 在Java.util下的一个接口,它是各种集合结构的父接口.继承与他的接口主要有Set 和List. Collection ...

  4. GitLab 502问题的解决

    问题: 502 Whoops, GitLab is taking too much time to respond. 日志: [root@cs12-66-gitlab ~]# my gitlab-ct ...

  5. RabbitMQ-官方指南-RabbitMQ配置

    原文:http://www.rabbitmq.com/configure.html RabbitMQ 提供了三种方式来定制服务器: 环境变量 定义端口,文件位置和名称(接受shell输入,或者在环境配 ...

  6. 【精】Linux磁盘I/O性能监控之iostat详解

    [精]Linux磁盘I/O性能监控之iostat详解 Linux命令详解----iostat 使用iostat分析IO性能

  7. tomcat启动窗口报错&&eclipse使用maven编译时报错

    tomcat启动窗口报错log4j:ERROR Could not find value for key log4j.appender.stdoutlog4j:ERROR Could not inst ...

  8. Java 运算符-=,+=混合计算详解

    +=与-=运算符混合计算解析: int x = 3; x += x -= x -= x += x -= x; 详解:算数运算按运算符优先级运算,从右至左计算. 1. x=x-x; 实际为 3 - 3 ...

  9. unity3d工程下的data file作用

    projectData文件夹中的data file: 1. Player settings – globalgamemanagers and globalgamemanagers.assets fil ...

  10. sqoop操作之HIVE导出到ORACLE

    示例数据准备 hive中创建dept表 create table dept( deptno int, dname string, loc string ) row format delimited f ...