Public list getorgan (stringOrgancode, StringOrganname){
String hsql;
List list;
If (organcode! = NULL & organcode. Length ()> 0 ){
Hsql = "from ab31 where bae002 =? And aab061 like? ";
List = gethibernatetemplate (). Find (hsql,New object [] {Organcode, '%' +Organname+ '% '});
}
Else {
Hsql = "from ab31 where aab061 like? ";
List = gethibernatetemplate (). Find (hsql, '%' + organname + '% ');
}
Return list;
}
When I like the query in hql, double quotation marks are combined according to SQL syntax."% '"+Organname+ "'%" Cannot find any results, so you must note that only single quotation marks can be used here, for example:'%' +Organname+ '%', Used for multiple [placeholders]New object [] {Organcode,Organname} To fill
Like syntax introduction:
% Represents any number of characters
_ Represents any character
[Abcdefg] indicates any character in it, only one
[^ C] indicates that the character in it does not contain c
[A-Z] indicates any one of the intervals, such as C or D.
[^ A-Z] indicates any of the non-intervals.
Escape '/' escape character, indicating that the character after/is not a special character.
Like '% item/% template % 'escape'/'to identify the special characters of the item % Template
Notes for like queries in hql