hql语句中like查询 对于 / ‘ ” % 的处理



hql语句中like查询 对于 / ‘ ” % 的处理 public List searchByParas(String authId, String resourceId, Integer state,
02. Integer value, String description) {
03. log.debug(“finding KiiUaResAuth instance by example”);
04. try {
05. description = description.replace(“//”, “//////”).replace(“%”, “//%”).replace(“‘”, “””);
06. StringBuffer hql = new StringBuffer(
07. “from KiiUaResAuth as k join k.id.resource as r where k.description like ‘%”
08. + description + “%’”);
09. if (authId != “”) {
10. hql.append(” and k.id.authId=’” + authId + “‘”);
11. }
12. if (resourceId != “”) {
13. hql.append(” and r.resourceId=’” + resourceId + “‘”);
14. }
15. if (state != null) {
16. hql.append(” and k.resAuthState=” + state);
17. }
18. if (value != null) {
19. hql.append(” and k.value=” + value);
20. }
21. if (description.indexOf(“//”) >= 0) {
22. hql.append(” escape ‘/’”);
23. }
24. List results = getHibernateTemplate().find(hql.toString());
25. log.debug(“find by example successful, result size: ”
26. + results.size());
27. List toresult = new ArrayList();
28. Object[] objlist = null;
29. if (results.size() != 0) {
30. for (int i = 0; i < results.size(); i++) {
31. Object objs = results.get(i);
32. objlist = (Object[]) objs;
33. if (objlist[0] != null) {
34. toresult.add((KiiUaResAuth) objlist[0]);
35. }
36. }
37. }
38. return toresult;
39. } catch (RuntimeException re) {
40. log.error("find by example failed", re);
41. throw new SystemException("UA1202");
42. }
43. }

http://blog.csdn.net/a9529lty/article/details/6688269