如何获取数据列表作为JSON字符串
问题描述:
内部列表并不返回一个JSON字符串..只有第一个数据表是回报...如何获取数据列表作为JSON字符串
有没有办法让所有的数据作为JSON字符串?
------我的方法---------------------
@RequestMapping(value="/mainreservationChart", method = RequestMethod.GET)
public ModelAndView getMRChartData(@ModelAttribute ("ReservationSummaryRQDTO") ReservationSummaryRQDTO search){
ReservationSummaryDTO returnDataDTO = new ReservationSummaryDTO();
MainReservationChartWSImpl wsImpl = MRWSUtil.getInstance().getWS_ServicePort();
search.setHotelCode("BBH");
search.setReportDate(toXmlDateGMT(new Date()));
returnDataDTO = wsImpl.getReservationSummary(search);
Map<String, Object> model = new HashMap<String, Object>();
model.put("status", true);
model.put("hotelCode", returnDataDTO.getHotelCode());
model.put("summary", returnDataDTO.getSummaryMonth());
model.put("data", returnDataDTO);
return new ModelAndView("jsonView", model);
}
的DTO
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "reservationSummaryDTO", propOrder = {
"hotelCode",
"summaryMonth"
})
public class ReservationSummaryDTO {
protected String hotelCode;
@XmlElement(nillable = true)
protected List<SummaryMonthDTO> summaryMonth;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "summaryMonthDTO", propOrder = {
"month",
"summaryType"
})
public class SummaryMonthDTO {
protected String month;
@XmlElement(nillable = false)
protected List<SummaryTypeDTO> summaryType;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "summaryTypeDTO", propOrder = {
"date",
"displaySequence",
"total",
"typeCode"
})
public class SummaryTypeDTO {
@XmlElement(nillable = true)
protected List<SummaryDateDTO> date;
protected Integer displaySequence;
protected Double total;
protected String typeCode;
答
试试这个
@RequestMapping(value="/mainreservationChart", method = RequestMethod.GET, headers = "Accept=application/json")
仍然没有得到完整的数据列表作为JSON string..adding以上是给我下面的错误HTTP状态406 ---由该请求所标识的资源只能生成与特性响应根据请求“接受”标题不可接受。 – Charitha 2013-05-10 03:52:16
你如何测试controlleres?使用休息客户端? – 2013-05-10 04:07:21
尝试添加Content-Type:application/json,Accept:application/json作为客户端的两个头部请求 – 2013-05-10 04:18:00