我应该转换为阳历和javascript中的方式吗?

时间:2015-03-03 19:54:08

标签: java javascript jquery ajax rest

我正在尝试使用ajax调用将数据传递到我的服务器。有两件物品正在通过;一组作为坐标的浮点数和一组作为字符串的日期。在后端,日期是XMLGregorianCalendar对象。我是否需要转换然后传递它们,如果我这样做,我将如何做?这是我的javascript函数,它调用ajax:

`getResourceNetworkByAoiTime: function(aoi,dateRange){


 var AreaOfInterest  = {eastLon:aoi[0],westLon: aoi[1],southLat:aoi[2],northLat:aoi[3]  };

  var LocalDateTimeRange ={start:dateRange[0],end:dateRange[1]};
  //var JData = {{eastLon:aoi[0],westLon: aoi[1],southLat:aoi[2],northLat:aoi[3]},{start:dateRange[0],end:dateRange[1]}};

  var DTO ={};
   DTO.AreaOfInterest = AreaOfInterest;
   DTO.LocalDateTimeRange =LocalDateTimeRange ;
     var self = this;
     $.ajax({
         cache: false,
         url: cdpeConfig.edcssUrl+"getAllResourceNetworksByAoiAndTime2/",
         type: 'GET',
         contentType:"application/json; charset=utf-8",
         dataType: "json",
        data:JSON.stringify(DTO),
       // data:jsonarg1+jsonarg2,
         success: function(data) {
          Alertify.dialog.alert('Successful AJAX resource network');
         }
       }).fail(function(jqXHR, textStatus, errorThrown) {
         sandbox.emit('error', { action: 'initialError', jqXHR: jqXHR });
       });
 }`

以下是javascript调用的方法:

public  List <ResourceNetwork> getAllResourceNetworksByAoiAndTime2(GetAllResourceNetworksByAoiAndTime aoi_dateRange){
ResourceNetworkServiceService resourcenetwork_service_service = new ResourceNetworkServiceService();
ResourceNetworkService resource_service resourcenetwork_service_service.getResourceNetworkServicePort();
List<ResourceNetwork> resource_networks = null;
AreaOfInterest aoi = new AreaOfInterest();
LocalDateTimeRange date_range = new LocalDateTimeRange();
aoi.setEastLon(aoi_dateRange.getArg0().getEastLon());
aoi.setWestLon(aoi_dateRange.getArg0().getWestLon());
aoi.setSouthLat(aoi_dateRange.getArg0().getSouthLat());
aoi.setNorthLat(aoi_dateRange.getArg0().getNorthLat());
date_range.setStart(aoi_dateRange.getArg1().getStart());
date_range.setEnd(aoi_dateRange.getArg1().getEnd());
resource_networks = resource_service.getAllResourceNetworksByAoiAndTime(aoi, date_range);
return resource_networks;
}

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

我假设aoi_dateRange.getArg1()。getStart()和aoi_dateRange.getArg1()。getEnd()应该返回从客户端传递到服务器的字符串转换产生的XMLGregorianCalendar对象。

此处描述了XMLGregorianCalendar对象的字符串表示形式:

http://docs.oracle.com/javase/7/docs/api/javax/xml/datatype/XMLGregorianCalendar.html#toXMLFormat() http://www.w3.org/TR/xmlschema-2/#dateTime-lexical-representation

例如,以下字符串应该有效(未测试):

2002-10-10T17:00:00Z

如果根据w3c规范中描述的词汇表示格式化时间,这应该有效(imho)。