关于接口调用的日期格式化问题
2017-03-10 11:17
399 查看
这两天改bug时候遇到一个很奇怪的问题,暂时没找到具体原因,先记录下来。
修改前的输出结果:
dubbo接口:
controller方法:
修改前是使用PO对象内部定义的
而另一个系统中的
public class AirTicketResourceBO implements Serializable{ private static final long serialVersionUID = 5469201963274216101L; private AirTicketResource po; private List<AirTicketLeg> legList; private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); private SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm"); private SimpleDateFormat legFormat = new SimpleDateFormat("HH:mm"); public String getStartDate(){ System.out.println("----------------------------------------------------"+DateUtils.format(this.po.getStartDate())); System.out.println("----------------------------------------------------"+DateUtils.format(po.getStartDate(), "yyyy-MM-dd")); return DateUtils.format(po.getStartDate(), "yyyy-MM-dd"); // return DateUtils.format(this.po.getStartDate()); } public String getEndDate(){ if (this.po.getEndDate()==null){return "";} // return DateUtils.format(this.po.getEndDate()); return DateUtils.format(po.getEndDate(), "yyyy-MM-dd"); } ... public String getLegHtml() throws ParseException{ if (this.legList == null){return "";} StringBuffer sb = new StringBuffer("<table class='air_ticket_leg'>"); for(int i=0; i<this.legList.size(); i++){ AirTicketLeg leg = this.legList.get(i); sb.append("<tr><td width='75'>").append(DateUtils.format(leg.getDepDate(),"yyyy-MM-dd")).append("</td><td>"); sb.append(leg.getAirCode()).append("</td><td>"); sb.append(leg.getDepCity()).append("-").append(leg.getArrCity()).append("</td>"); String depTime=(leg.getDepTime()==null)?"":DateUtils.format(leg.getDepTime(),"HH:mm"); String arrTime=(leg.getArrTime()==null)?"":DateUtils.format(leg.getArrTime(),"HH:mm"); sb.append("<td>").append(depTime).append("-").append(arrTime).append("</td></tr>"); } sb.append("</table>"); //格式化方式对比 // for(int i=0; i<this.legList.size(); i++){ // AirTicketLeg leg = this.legList.get(i); // sb.append("<tr><td width='75'>").append(sdf.format(leg.getDepDate())).append("</td><td>"); // sb.append(leg.getAirCode()).append("</td><td>"); // sb.append(leg.getDepCity()).append("-").append(leg.getArrCity()).append("</td>"); // String depTime=(leg.getDepTime()==null)?"":legFormat.format(leg.getDepTime()); // String arrTime=(leg.getArrTime()==null)?"":legFormat.format(leg.getArrTime()); // sb.append("<td>").append(depTime).append("-").append(arrTime).append("</td></tr>"); // } return sb.toString(); }
//dubbo接口 @Override public TicketListResult ticketList(Integer bizId, Integer id) { AirTicketResource resourcePo = airTicketResourceBiz.findResource(id, bizId); AirTicketResourceBO resourceBo = new AirTicketResourceBO(resourcePo); resourceBo.setLegList(airTicketResourceBiz.findLegsByResourceId(resourceBo.getPo().getId())); List<AirTicketRequest> requestList = airTicketRequestBiz.findRequestsByResource(id, bizId); List<AirTicketRequestBO> boList = new ArrayList<AirTicketRequestBO>(); for (int i=0; i<requestList.size(); i++){ AirTicketRequest po = requestList.get(i); po.setResource(resourcePo); AirTicketRequestBO bo = new AirTicketRequestBO(po); bo.setGroupOrder(groupOrderBiz.findById(po.getGroupOrderId())); bo.go.setGroupOrderGuestList(groupOrderGuestBiz.selectByOrderId(po.getGroupOrderId())); boList.add(bo); } TicketListResult result = new TicketListResult(); result.setResourceBo(resourceBo); result.setBoList(boList); return result; }
//Controller方法 @RequestMapping("ticketList.htm") /* @RequiresPermissions(PermissionConstants.AIR_TICKET_RESOURCE) */ public String ticketList(HttpServletRequest request, HttpServletResponse reponse, ModelMap model, Integer id){ Integer bizId = WebUtils.getCurBizId(request); TicketListResult result = requestFacade.ticketList(bizId, id); model.addAttribute("resource", result.getResourceBo()); model.addAttribute("boList", result.getBoList()); return "airticket/ticket_list"; }
修改前的输出结果:
dubbo接口:
<table class='air_ticket_leg'><tr><td width='75'> 2017-02-02 ---------- </td><td>MU5734</td><td>昆明-丽江</td><td> 19:40-20:35 ----------- </td></tr></table>
controller方法:
<table class='air_ticket_leg'><tr><td width='75'> 17-2-2 上午12:00 -------------- </td><td>MU5734</td><td>昆明-丽江</td><td> 17-2-2 下午7:40-17-2-2 下午8:35 --------------------------- </td></tr></table>
修改前是使用PO对象内部定义的
SimpleDateFormat类,修改后使用的自定义工具类
DateUtils,但是结果完全不一样。
而另一个系统中的
AirTicketResourceBO类放在web工程中,没有实现序列化接口,格式化结果没有问题。
相关文章推荐
- 关于日期格式化的一个小问题
- 关于使用LayoutParams清除设置以及DateFormat无法正确转换格式化日期的问题
- SpringMVC在使用Jackson2时关于日期类型格式化的问题
- 关于调用微信上传素材接口返回41005错误的问题
- 关于日期格式化的一个小问题
- 关于vs2010下编译dll动态库,JNA接口在java中调用的问题
- SpringMVC在使用Jackson2时关于日期类型格式化的问题
- 关于处理日期格式化问题遇到的一个坑
- EasyNVR RTSP转RTMP-HLS流媒体服务器前端构建之_关于接口调用常见的一些问题(401 Unauthorized)
- 关于微信js接口调用时,token效期问题
- 关于facebook接口调用返回unknow error的问题
- 关于微信支付IWXAPIEventHandler接口中onresp不能调用的问题
- 关于spring-mvc中使用ajax调用后台接口出现400 bad request的问题解决方案
- EasyNVR RTSP转RTMP-HLS流媒体服务器前端构建之:关于接口调用常见的一些问题(401 Unauthorized)
- SpringMVC在使用Jackson2时关于日期类型格式化的问题
- EasyNVR RTSP转RTMP-HLS流媒体服务器前端构建之_关于接口调用常见的一些问题(401 Unauthorized)
- 关于微信 调用js-sdk接口报错的问题
- 关于百度APIStore提供的接口调用失败问题
- iOS关于日期格式化字符串的问题
- 关于 php 调用 其他语言写的Web Service SOAP 接口的参数传递问题