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