zoukankan      html  css  js  c++  java
  • jsp自定义标签

    1.controller中查出数据
    Map<String, Object> custom = customersController.basic(custId);
    model.put("customer", custom);

    2.JSP中接收code值调用自定义标签
    <div class="profile-info-name"> 居住城市:</div>
        <div class="profile-info-value">
            <span>${fns:getCity(customer.lifeCode)}</span>
        </div>

    3.fns.tld自定义标签
    <?xml version="1.0" encoding="UTF-8" ?>
    <taglib xmlns="http://java.sun.com/xml/ns/j2ee"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
            version="2.0">
        <function>
            <description>根据城市编码获取城市</description>
            <name>getCity</name>
            <function-class>com.loan.admin.web.utils.RestApiUtil</function-class>
            <function-signature>java.lang.String getCity(java.lang.String)</function-signature>
            <example>${fns:getCity(object)}</example>
        </function>
    </taglib>

    4.调用【com.loan.admin.web.utils.RestApiUtil】下getCity方法
        public static String getCity(String code){
            try {
                String name = "";
                String cityName = "";
                List<String> list = new ArrayList();
                Map<String, Object> params = Maps.newLinkedHashMap();
                while(!"0".equals(code)&&!"".equals(code)&&code!=null){
                    params.put("code", code);
                    String resp = RestApiUtil.doPost("loan/user/findChinaRegion/", params);
                    JSONObject jsonObject = JSONObject.parseObject(resp);
                    if(null!=jsonObject.get("result")&&!"".equals(jsonObject.get("result"))){
                        code = jsonObject.getJSONObject("result").getString("parentCode");
                        name = jsonObject.getJSONObject("result").getString("name");
                        list.add(name);
                    }else{
                        break;
                    }
                }
                for(int i=0;i<list.size();i++){
                    cityName = list.get(i).toString() + cityName;
                }
                return  cityName;
            }catch (Exception e){
                return "";
            }
        }

  • 相关阅读:
    Jmeter 脚本录制
    Scrapy 爬虫模拟登陆的3种策略
    Scrapy Shell
    Ipython
    XPath helper
    python3 接口测试数据驱动之操作mysql数据库
    Pandas 基础(17)
    Pandas 基础(16)
    在 Laravel 项目中使用 Elasticsearch 做引擎,scout 全文搜索(小白出品, 绝对白话)
    Pandas 基础(15)
  • 原文地址:https://www.cnblogs.com/anjunshuang/p/9293991.html
Copyright © 2011-2022 走看看