java接口实现过程

来源:互联网 发布:mdms-vb香蕉筛工作原理 编辑:程序博客网 时间:2024/05/18 13:09

 接口实现过程: 通过前台GET方法将参数传至JSP页面,由Jsp页面封装后传参调用后台方法,然后为前台返回<Items><Item>....</Item></Items>格式xml语句(在JSP页面打印出来)

URL: localhost:8080/xxx/xxx.jsp?Action=searchGetEntList&SysID=?&StreetID=?......

        //前台
        if (action.contains("searchGetEntList")) {
            String SysID = request.getParameter("SysID");
            String StreetID = request.getParameter("StreetID");
            String Key = request.getParameter("Key");
            String Name = request.getParameter("Name");
            out.print(service.getSearchGetEntList(SysID, StreetID, Key, Name));
        }

//后台

  public String getSearchGetEntList (String SysID,String StreetID,String Key,String Name) {

        // TODO add the real code
        String xml = "<Items>";
        //查询执法人员
        String sql1 = "select e.ent_serial,e.name,p.account_id from table1 t,table2 e,table3 p where 1=1 and e.subdistrict_id='"+StreetID+"' and e.name like '%"+Key+"%' and t.orgnid='"+SysID+"' and t.id=e.subdistrict_id and t.orgnid=p.orgnid and p.account_id='"+Name+"' and e.flag='2'";
        //链接数据库
        SimpleJDBCOperator operator = new SimpleJDBCOperator();
        List<Map<String, Object>> list = operator.GetList(sql1);
        if (list != null && list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> map = list.get(i);
                String name = map.get("NAME") == null ? "" : map.get(
                        "NAME").toString();
                String ent_serial = map.get("ENT_SERIAL") == null ? "" : map
                        .get("ENT_SERIAL").toString();
                xml += "<Item>";
                xml += "<EntID>" + ent_serial + "</EntID>";
                xml += "<EntTitle>" + name + "</EntTitle>";
                xml += "</Item>";
            }
        }
        xml += "</Items>";
        return xml;
    }