49,924
社区成员




public String getTaskInfoById(){
log.info("根据ID查询任务信息-开始-action-getTaskInfoById");
Map<String, String> jsonMap = new HashMap<String, String>();
try{
Task dd = taskService.getTaskById(task.getId());
//对象转json时,对象中日期格式数据不能为空
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
dd.setFromDate(sdf.parse("1990-01-01"));
dd.setToDate(sdf.parse("2500-01-01"));
result = JSONObject.fromObject(dd);
}catch(Exception e){
jsonMap.put("resultdsc", "查询任务信息出错");
jsonMap.put("result", "false");
result = JSONObject.fromObject(jsonMap);
log.debug("查询任务信息异常:"+e.getMessage());
}
log.info("根据ID查询任务信息-结束-action-getTaskInfoById");
return SUCCESS;
}
User user = new User();
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
System.out.println(mapper.writeValueAsString(user));
这样不会输出 null 的属性