spring - How to send information from a server to Android -
i've got server. how can send information server android app? 1 of controller methods:
@requestmapping("/city/{cityid}") public modelandview showcity(@pathvariable("cityid") int cityid){ modelandview mav=new modelandview("city/citydetails"); mav.addobject(this.whatsnewservice.findcitybyid(cityid)); return mav; }
i case can not pass modelandview (actually can). best option use rest. can make method rest api method. , pass jason object.
in general, web applications expose service through rest api used third part applications or power mobile applications
@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); } }
or can use same @controller
class ,
@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); } }
in android client side can use retrofit library map josn object application object.
Comments
Post a Comment