union表关联模糊查询servlet,action方法

时间:2024-01-15 12:47:14

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;
    }