Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将信息从服务器发送到Android_Android_Spring_Web Services - Fatal编程技术网

如何将信息从服务器发送到Android

如何将信息从服务器发送到Android,android,spring,web-services,Android,Spring,Web Services,我有一台服务器。如何将信息从服务器发送到我的Android应用程序?这是我的控制器方法之一: @RequestMapping("/city/{cityId}") public ModelAndView showCity(@PathVariable("cityId") int cityId){ ModelAndView mav=new ModelAndView("city/cityDetails"); mav.addObject(this.whatsNewService.findC

我有一台服务器。如何将信息从服务器发送到我的Android应用程序?这是我的控制器方法之一:

@RequestMapping("/city/{cityId}")
public ModelAndView showCity(@PathVariable("cityId") int cityId){
    ModelAndView mav=new ModelAndView("city/cityDetails");
    mav.addObject(this.whatsNewService.findCityById(cityId));
    return mav;
}

在这种情况下,您不能传递ModelAndView(实际上您可以)。但最好的选择是使用REST。您可以将此方法设置为RESTAPI方法。并传递一个Jason对象

一般来说,web应用程序通过RESTAPI公开其服务,供第三方应用程序使用或为其移动应用程序供电

@RestController
public class CityController {

   @Autowire
   private WhatsNewService whatsNewService;

   @RequestMapping(method = RequestMethod.GET, value = "/city/{cityId}")
   public City showCity(@PathVariable("cityId") int cityId){

    return this.whatsNewService.findCityById(cityId);
   }

}
或者您可以使用相同的
@Controller
类和

@Controller
public class CityController {

   @Autowire
   private WhatsNewService whatsNewService;

   @RequestMapping(method = RequestMethod.GET, value = "/city/{cityId}")
   public @ResponseBody City showCity(@PathVariable("cityId") int cityId){

    return this.whatsNewService.findCityById(cityId);
   }

}

在android客户端,您可以使用类似翻新的库将您的josn对象映射到应用程序对象。

I在这种情况下,您不能传递ModelAndView(实际上您可以)。但最好的选择是使用REST。您可以将此方法设置为RESTAPI方法。并传递一个Jason对象

一般来说,web应用程序通过RESTAPI公开其服务,供第三方应用程序使用或为其移动应用程序供电

@RestController
public class CityController {

   @Autowire
   private WhatsNewService whatsNewService;

   @RequestMapping(method = RequestMethod.GET, value = "/city/{cityId}")
   public City showCity(@PathVariable("cityId") int cityId){

    return this.whatsNewService.findCityById(cityId);
   }

}
或者您可以使用相同的
@Controller
类和

@Controller
public class CityController {

   @Autowire
   private WhatsNewService whatsNewService;

   @RequestMapping(method = RequestMethod.GET, value = "/city/{cityId}")
   public @ResponseBody City showCity(@PathVariable("cityId") int cityId){

    return this.whatsNewService.findCityById(cityId);
   }

}

在android客户端,您可以使用类似翻新的库将您的josn对象映射到应用程序对象。

改进了拼写和语法改进了拼写和语法