list<实体类>嵌套list<实体类>,必须保证嵌套的实体类里面有这个list对象,把这个list<实体类>当做一个对象
这是需要解析的数据,并把这些数据封装成list<实体类>对象,传给前台
<root> <RETURN_CODE>0RETURN_CODE> <RETURN_DESC>成功!RETURN_DESC> <RETURN_INFO> <order_info> <so_nbr>7004519so_nbr> <cust_id>2028814cust_id> <appl_date>2019-03-21 15:27:56appl_date> <compl_date>nullcompl_date> <deal_staff_name>nulldeal_staff_name> <deal_staff_mobile>nulldeal_staff_mobile> <compl_phenom>无法打开互动电视页面compl_phenom> <fault_reason>nullfault_reason> <book_date>2019-04-19 14:00:00book_date> <book_time>14:00--18:00book_time> <run_sts>待处理run_sts> <deal_log> <deal_info>
<deal_time>2019-03-29 08:58:27deal_time><deal_type>领单deal_type><deal_name>王超群deal_name><deal_mobile>nulldeal_mobile>
deal_info> <deal_info>
<deal_time>2019-03-29 09:00:04deal_time><deal_type>回单deal_type><deal_name>王超群deal_name><deal_mobile>nulldeal_mobile>
deal_info> <deal_info>
<deal_time>2019-03-22 17:01:57deal_time><deal_type>定单生成deal_type><deal_name>系统deal_name><deal_mobile>nulldeal_mobile>
deal_info> deal_log> order_info> <order_info> <so_nbr>7004505so_nbr> <cust_id>2028814cust_id> <appl_date>2019-04-19 08:48:50appl_date> <compl_date>nullcompl_date> <deal_staff_name>nulldeal_staff_name> <deal_staff_mobile>nulldeal_staff_mobile> <compl_phenom>整体网速慢compl_phenom> <fault_reason>nullfault_reason> <book_date>2019-04-19 08:30:00book_date> <book_time>08:30--12:00book_time> <run_sts>待处理run_sts> <deal_log> <deal_info>
<deal_time>2019-04-19 08:49:02deal_time><deal_type>定单生成deal_type><deal_name>系统deal_name><deal_mobile>nulldeal_mobile>
deal_info> deal_log> order_info> RETURN_INFO> root>
下面是实体类,为了节省空间get、set方法没写;如果不写toString()方法,看不到数据
public class OrderInfo { /** * 定单号 */ private String soNbr; /** * 客户证号 */ private String custId; /** * 受理时间 */ private String applDate; /** * 完成时间 */ private String complDate;/** * dealLogInfo */ private ListdealLogInfo; }
public class DealLogInfo { /** * 操作时间 yyyy-mm-dd hh24:mi:ss */ private String dealTime; /** * 操作类型 */ private String dealType; /** * 操作人 */ private String dealName; /** * 操作人联系方式 */ private String dealMobile; }
逻辑代码,不全
ListorderList = new ArrayList (); //存储到list实体类集合 OrderInfo or = new OrderInfo(); orderList.add(or); or.setApplDate(appl_date); or.setBookDate(book_date); or.setBookTime(book_time); List dealInfoList = new ArrayList (); DealLogInfo deal = new DealLogInfo(); dealInfoList.add(deal); for (Element element : dealList) { deal.setDealTime(deal_time); deal.setDealType(deal_type); deal.setDealName(deal_name); deal.setDealMobile(deal_mobile); } or.setDealLogInfo(dealInfoList);
request.setAttribute("orderList", orderList);
前台取值
遇到的错误:
el表达式获取list数据报错:java.lang.NumberFormatException:For input string: "xxx"
后来查询资料,是由于list会默认将后面的数据当做下标读取,会出现这个情况
错误代码:
<c:forEach items="${orderList}" var="orderList" > <ul > <li> <div>客户证号:div> <div>${orderList.custId}div> li> <li> <div>故障现象:div> <div>${orderList.complPhenom}div> li> ul> <ul> <li class="title color-6">派单li> <li class="detail color-9"> <p>${orderList.dealLogInfo.dealTime}p> li> ul> c:forEach>
正确代码
只要标明下标或者再次foreach遍历roles的list就可以了
<c:forEach items="${orderList}" var="orderList" > <ul > <li> <div>客户证号:div> <div>${orderList.custId}div> li> <li> <div>故障现象:div> <div>${orderList.complPhenom}div> li> ul> <c:forEach items="${orderList.dealLogInfo}" var="dealLogInfo"> <ul> <li class="title color-6">派单li> <li class="detail color-9"> <p>${dealLogInfo.dealTime}p> li> ul> c:forEach> c:forEach>
页面需要引入c标签代码,否则也会爆这个错误
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> doctype html> <html lang="en"> <% String openId = request.getAttribute("openId") == null ? "" : request.getAttribute("openId").toString(); String area_id = request.getAttribute("area_id") == null ? "" : request.getAttribute("area_id").toString(); String customercode = request.getAttribute("cust_id") == null ? "" : request.getAttribute("cust_id").toString(); %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>