<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-alt:"Calisto MT"; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 159 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-alt:"Century Gothic"; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:"Times New Roman"; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:widow-orphan; font-size:10.5pt; font-family:"Calibri","sans-serif"; mso-fareast-font-family:宋体; mso-bidi-font-family:宋体;} a:link, span.MsoHyperlink {mso-style-priority:99; color:blue; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {mso-style-noshow:yes; mso-style-priority:99; color:purple; mso-themecolor:followedhyperlink; text-decoration:underline; text-underline:single;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt; mso-ascii-font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman"; mso-hansi-font-family:"Times New Roman"; mso-font-kerning:0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->
select * from USERS where USER_NAME like '%wang%'; 这种like 语句在ibatis 中怎么写,项目是用ibatis 作为持久层的框架。
<select id="showOneStudentByName" parameterClass="String" resultMap="studentORM">
select * from t_stu where s_name like #name#
</select>
这样写显然不行
在调用中需要在参数的前后加上%, 比如这样:
return sqlMapper.queryForList("Student.showOneStudentByName", "%"+name+"%"); 这样可行,但总显得有些不协调。
最后针对oracle 数据库写法为:
<select id="showOneStudentByName" parameterClass="String" resultMap="studentORM">
select * from t_stu where s_name like '%'||#name#||'%'
</select>
在调用的时候 就不用去前后加% 了。
注意:sql 语句不要写成select * from t_stu where s_name like '%$name$%', 这样极易受到注入攻击。
补充说明一下:
对于不同数据字符串连接符不一样。列举mysql 和SQLServer 如下:
Mysql :
SELECT *
FROM user
WHERE username like CONCAT('%', #username#, '%')
SQLServer :
SELECT *
FROM user
WHERE username like '%' + #username# + '%'
原文参考:http://blog.csdn.net/ITshu/archive/2008/10/28/3168620.aspx
另外: , 分隔开的 bean 值可以使用 str2NumList 或 str2VarList 以代替之前的 $a$ 形式
如果表的字段类型是 number ,则使用 str2NumList
如果表的字段类型是 varchar2 ,则使用 str2VarList