如何将信息从服务器发送到Android
我有一台服务器。如何将信息从服务器发送到我的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
@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对象映射到应用程序对象。改进了拼写和语法改进了拼写和语法