自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iBATIS教程之like語句的寫法淺析

開發(fā) 后端
iBATIS教程之like語句的寫法到底是怎么樣子的呢?網(wǎng)上有很多的例子,那么本文將會介紹一些在實際中用到的iBATIS中l(wèi)ike語句的寫法的一點體會。

iBATIS教程之like語句的使用我們可以先看看網(wǎng)上搜了一下iBATIS的關(guān)于like的使用

  1. select * from USERS where USER_NAME like '%wang%'

這種like語句在iBATIS中怎么寫,項目是用iBATIS作為持久層的框架。

  1. ﹤select id="showOneStudentByName" parameterClass="String" resultMap="studentORM﹥" 
  2. select * from t_stu where s_name like #name#  
  3. ﹤/select﹥ 

這樣寫顯然不行

在調(diào)用中需要在參數(shù)的前后加上%,比如這樣:

  1. return sqlMapper.queryForList("Student.showOneStudentByName""%"+name+"%"); 

這樣可行,但總顯得有些不協(xié)調(diào)。

最后針對Oracle數(shù)據(jù)庫寫法為:

  1. select id="showOneStudentByName" parameterClass="String" resultMap="studentORM"﹥  
  2. select * from t_stu where s_name like '%'||#name#||'%'   
  3. ﹤/select﹥  

在調(diào)用的時候就不用去前后加%了。

注意:SQL語句不要寫成select * from t_stu where s_name like '%$name$%',這樣極易受到注入攻擊。

補(bǔ)充說明一下:

對于不同數(shù)據(jù)字符串連接符不一樣。列舉mysql和SQLServer如下:

Mysql: 

  1. SELECT *   
  2.  
  3. FROM user   
  4.  
  5. WHERE username like CONCAT('%', #username#, '%')  

SQLServer:

  1. SELECT *   
  2.  
  3. FROM user   
  4.  
  5. WHERE username like '%' + #username# +  '%'  

關(guān)于數(shù)據(jù)庫字符串連接符簡單列舉我使用過的一些數(shù)據(jù)庫如下圖:

數(shù)據(jù)庫字符串連接符 

iBATIS教程之like語句的使用就向你介紹到這里,希望對你有所幫助。

責(zé)任編輯:仲衡 來源: CSDN博客
相關(guān)推薦

2009-07-17 09:44:40

iBATIS教程

2009-07-21 14:24:46

iBATIS教程

2009-07-21 15:46:48

獲得output參數(shù)值iBATIS教程

2009-07-21 11:12:00

iBATIS配置

2009-07-17 10:59:59

iBATIS接口

2009-07-16 13:51:47

iBATIS測試類

2009-07-15 17:58:07

iBATIS 動態(tài)映射

2009-07-16 10:23:30

iBATIS工作原理

2009-07-22 10:42:59

iBATIS Cach

2009-07-17 10:32:45

iBATIS MapB

2009-07-22 10:03:11

iBATIS Resu

2009-07-16 09:14:26

iBATIS DAO

2009-07-20 18:00:16

iBATIS DAO事

2009-07-15 17:19:31

iBATIS Ecli

2009-07-22 13:04:41

iBATIS動態(tài)查詢

2009-07-22 16:02:14

iBATIS參數(shù)

2009-07-22 15:01:01

iBATIS SQLM

2009-07-16 13:08:09

iBATIS快速創(chuàng)建應(yīng)

2009-07-17 17:05:44

iBATIS緩存cacheModel

2009-07-22 15:21:00

iBATIS SQLM
點贊
收藏

51CTO技術(shù)棧公眾號