{"rsdb":{"rid":"156663","subhead":"","postdate":"0","aid":"117583","fid":"54","uid":"1","topic":"1","content":"

\u5728web\u9879\u76ee\u4e2d\uff0c\u663e\u793a\u6570\u636e\u4e00\u822c\u91c7\u7528\u5206\u9875\u663e\u793a\u7684\uff0c\u5728\u5206\u9875\u7684\u540c\u65f6\uff0c\u7528\u6237\u53ef\u80fd\u8fd8\u6709\u641c\u7d22\u7684\u9700\u6c42\uff0c\u4e5f\u5c31\u662f\u6a21\u7cca\u67e5\u8be2\uff0c\u6240\u4ee5\uff0c\u6211\u4eec\u8981\u5728dao\u5199\u4e00\u4e2a\u53ef\u4ee5\u5206\u9875\u5e76\u4e14\u53ef\u4ee5\u52a8\u6001\u52a0\u6761\u4ef6\u67e5\u8be2\u7684\u65b9\u6cd5\u3002\u5206\u9875\u6bd4\u8f83\u7b80\u5355\uff0c\u91c7\u7528hibernate\u63d0\u4f9b\u7684\u5206\u9875\uff0c\u52a8\u6001\u6761\u4ef6\u91c7\u7528map(\u201c\u5b57\u6bb5\u201d\uff0c\u6a21\u7cca\u503c)\u5c01\u88c5\u67e5\u8be2\u6761\u4ef6\uff0cmap\u53ef\u4ee5\u6dfb\u52a0\u591a\u4e2a\u67e5\u8be2\u6761\u4ef6\uff0c\u662f\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\uff0c\u4ece\u800c\u8fbe\u5230\u5b9e\u73b0\u5206\u9875\u5e76\u6a21\u7cca\u67e5\u8be2\u3002<\/p>

@Override
? ? public List findPage(int page, int length, Map pram) {
? ? ? ? List result = null;?
? ? ? ? try?
? ? ? ? {?
?\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000 \/\/\u521d\u59cb\u5316hql\uff0cthis.entityClazz.getSimpleName()\u662f\u6cdb\u578b\u7684\u771f\u5b9e\u7c7b\u540d\uff0c\u5728\u6784\u9020\u51fd\u6570\u4e2d\u83b7\u53d6
? ? ? ? ? ? ? String hql = \"from \" + this.entityClazz.getSimpleName() +? \" where 1=1 and \"; \/\/\u6ce8\u610f\u7a7a\u683c
? ? ? ? ? ? ? Session session = this.sesionFactory.openSession(); \/\/\u83b7\u53d6\u8fde\u63a5
? ? ? ? ? ? ? if(!pram.isEmpty())? \/\/\u5224\u65ad\u6709\u65e0\u6761\u4ef6
? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? Iterator it = pram.keySet().iterator();? \/\/\u8fed\u4ee3map
? ? ? ? ? ? ? ? ? while(it.hasNext())
? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? String key = it.next(); \/\/\u83b7\u53d6\u6761\u4ef6map\u4e2d\u7684key\uff0c\u5373\u6761\u4ef6\u5b57\u6bb5
? ? ? ? ? ? ? ? ? ? ? hql = hql + key + \" like \" + \"'%\" + pram.get(key) + \"%'\" + \" and \";? \/\/\u5c06\u5b57\u6bb5\u548c\u6a21\u7cca\u503c\u62fc\u63a5\u6210hql
? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? }
? ? ? ? ? ? ?
? ? ? ? ? ? ? hql += \" 2=2\"; \/\/\u5728hql\u672b\u5c3e\u52a0\u4e0a 2=2,\u65b9\u4fbfhql\u518d\u6b21\u62fc\u63a5
? ? ? ? ? ? ? System.out.println(hql);
? ? ? ? ? ? ? Query query = session.createQuery(hql);
? ? ? ? ? ? ? query.setFirstResult((page - 1) * length); \/\/\u8bbe\u7f6e\u5206\u9875\u9875\u7801?
? ? ? ? ? ? ? query.setMaxResults(length);? \/\/\u8bbe\u7f6e\u6bcf\u9875\u6570\u636e\u957f\u5ea6
? ? ? ? ? ? ? result = query.list(); \/\/\u8fd4\u56de\u7ed3\u679c\u96c6
? ? ? ? ? ? ?
? ? ? ? } catch (RuntimeException re)?
? ? ? ? {?
? ? ? ? ? ? throw re;?
? ? ? ? }?
? ? ? ?
? ? ? ? return result;? <\/p>

? ? }<\/p>","orderid":"0","title":"Hibernate\u5206\u9875\u6a21\u7cca\u67e5\u8be2","smalltitle":"","mid":"0","fname":"linux\u7f16\u7a0b\u57fa\u7840","special_id":"0","bak_id":"0","info":"0","hits":"424","pages":"1","comments":"0","posttime":"2017-03-03 08:15:44","list":"1488500144","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"Hibernate<\/A> \u6a21\u7cca<\/A> \u67e5\u8be2<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"14.17.22.31","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"Hibernate\u5206\u9875\u6a21\u7cca\u67e5\u8be2","lastview":"1709244944","digg_num":"7500","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}