自己建了一个实体类
public class MissPoint implements Serializable{ private static final long serialVersionUID = -3623219494524321164L; /*** 时间*/
private String date; /*** 酒店数 */
private Integer count; /*** 酒店id*/
private List<Integer> hotelList; /**需要查询的时间**/
private Date occurDate; /**所有漏点的数据**/
private List<DataMap> maps ; private Map<Date, List<Integer>> data = new HashMap<Date, List<Integer>>(); public MissPoint() {
// TODO Auto-generated constructor stub
} public MissPoint(Date date,List<DataMap> maps) {
// TODO Auto-generated constructor stub
this.occurDate = date;
this.maps = maps;
} private void setData(){
for(DataMap map : maps){
int hotelid = map.getInt("hotel_id");
List<Integer> indexList = DataPointHelper.findByIsZero(map.get("text"), 0, -1); for(Integer index : indexList){
Date pointDate = DataPointHelper.getTimeByIndex(occurDate, index); if(data.containsKey(pointDate)){
data.get(pointDate).add(hotelid);
}else{
List<Integer> list = new ArrayList<Integer>();
list.add(hotelid);
data.put(pointDate, list);
}
}
}
} public List<MissPoint> getList(){
List<MissPoint> missPoints = new ArrayList<MissPoint>();
this.setData();
for(Map.Entry<Date, List<Integer>> entry : data.entrySet()){
MissPoint point = new MissPoint();
point.setDate(DateHelper.format(entry.getKey(), "yyyy-MM-dd HH:mm:ss"));
point.setCount(entry.getValue().size());
point.setHotelList(entry.getValue()); missPoints.add(point);
}
return missPoints;
} @Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((date == null) ? 0 : date.hashCode());
return result;
} public String getDate() {
return date;
} public void setDate(String date) {
this.date = date;
} public Integer getCount() {
return count;
} public void setCount(Integer count) {
this.count = count;
} public List<Integer> getHotelList() {
return hotelList;
} public void setHotelList(List<Integer> hotelList) {
this.hotelList = hotelList;
} @Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
MissPoint other = (MissPoint) obj;
if (date == null) {
if (other.date != null)
return false;
} else if (!date.equals(other.date))
return false;
return true;
} @Override
public String toString() {
return "[date=" + date + ", count=" + count
+ ", hotelList=" + hotelList + "]";
} }
其中给外界提供的方法写成了getList(),转json的时候一直报错,此类的list属性为空,纳闷了,找了半天没有找到名为list的属性,后来突发奇想,是不是那个getList(),让他以为我是获取属性list的值,但是又没有那个属性,所以空指针了,只能这么理解了,不知道对不对,反正改了方法名就不在报错了