union表关联模糊查询servlet,action方法
Posted yanchaohui
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了union表关联模糊查询servlet,action方法相关的知识,希望对你有一定的参考价值。
2018-11-14
servletxml层
public String getSql(String keyword) { StringBuffer sqlSb = new StringBuffer(); if(null!=keyword&&!"".equals(keyword)) { sqlSb.append("SELECT perfile,repername,decdate,permitorg,publicdate,perid FROM es_ent_permit WHERE permitorg IS NOT NULL AND permitorg != ‘‘ AND perfile LIKE ‘%"); sqlSb.append(keyword); sqlSb.append("%‘ OR repername LIKE ‘%"); sqlSb.append(keyword); sqlSb.append("%‘"); sqlSb.append(" UNION "); sqlSb.append("SELECT entname,repername,decdate,punorg,publicdate,punid FROM es_ent_punish WHERE punorg IS NOT NULL AND punorg != ‘‘ AND entname LIKE ‘%"); sqlSb.append(keyword); sqlSb.append("%‘ OR repername LIKE ‘%"); sqlSb.append(keyword); sqlSb.append("%‘"); }else { sqlSb.append("SELECT perfile,repername,decdate,permitorg,publicdate,perid FROM es_ent_permit "); sqlSb.append(" UNION "); sqlSb.append("SELECT entname,repername,decdate,punorg,publicdate,punid FROM es_ent_punish "); } System.out.println(sqlSb.toString()); return sqlSb.toString(); }
action层
return 页面
protected static final String PUB_INDEX_SELECT_JSP = "/doupub/xxx.jsp";
action方法
public String findPunishPermitInfoBydep(){ String keywords = this.getParameterToPage("keywords"); PageRequest pageRequest = newPageRequest(null); String pageNumber = this.getParameterToPage("pageNumber"); pageRequest.setPageSize(PAGE_SIZE); if(!"".equals(pageNumber)){ pageRequest.setPageNumber(new Integer(pageNumber)); } System.out.println(esEntPermitManager.getSql(keywords)); try{ Page page = esEntPermitManager.getEntityDao().findPageObjectListBySql(esEntPermitManager.getSql(keywords), pageRequest); this.savePage(page); }catch(Exception e){ e.printStackTrace(); } return PUB_INDEX_SELECT_JSP; }
以上是关于union表关联模糊查询servlet,action方法的主要内容,如果未能解决你的问题,请参考以下文章
mysql合并查询(多张表) union 和 union all
SQL Fundamentals || 多表查询(内连接,外连接(LEFT|RIGHT|FULL OUTER JOIN),自身关联,ON,USING,集合运算UNION)