---
title: "IBatis的like查询写法"
author: "NumbCoder"
date: "2010-04-30T11:41:46Z"
tags: []
categories: ["企业架构"]
slug: "ibatis-like"
draft: false
lastmod: "2010-04-30T11:43:38Z"
id: 656873
url: "https://numbcoder.iteye.com/blog/656873"
---

在《ibatis in action》一书里明确提到了使用iBatis like查询的时候，用下面这种写法会有注入漏洞

```
 select * from  t_user   where  username  like '%$name$%' 
```

 所以正规的安全写法（参照网上搜集的）

```
MySql:  select * from t_user  where  username  like concat('%',#name#,'%')  
    
Oracle:  select * from t_user where  username  like '%'||#name#||'%'    

SQL Server:  select * from t_user  where  username  like '%'+#name#+'%'  
```