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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -