The
Code is as follows:
Import Org.springframework.stereotype.Controller;
Import Org.springframework.web.bind.annotation.RequestBody;
Import org.springframework.web.bind.annotation.RequestMapping;
Import Org.springframework.web.bind.annotation.RequestMethod;
Import Org.springframework.web.bind.annotation.ResponseBody;
Import Org.springframework.web.client.RestTemplate;
Import Java.util.Date;
Import Java.util.HashMap;
Import Java.util.Map; /** * @author Administrator */@Controller @RequestMapping (value = "/test") public class TestController {@Reque Stmapping (value = "/object", method = Requestmethod.post) @ResponseBody The Public String object (@RequestBody Location Model model) {return model.getlongitude () + "" + model.getlatitude () + "" + Model.getcreateby () + "" + MODEL.G
Etcreatetime (); @RequestMapping (value = "/map", method = Requestmethod.post) @ResponseBody The public String map (@RequestBody M Ap<string, string> map) {String CreateBy = Map.get ("CreaTeby ");
return CreateBy; @RequestMapping (value = "/date", method = Requestmethod.post) @ResponseBody The public String map (@RequestBody
Date date) {return date.tostring ();
@RequestMapping (value = "/test_object") @ResponseBody public String Callwsobject () {try {
Resttemplate template = new Resttemplate ();
String url = "Http://localhost:8080/location/object";
Locationmodel model = new Locationmodel ();
Model.setlongitude ("110.234567");
Model.setlatitude ("222.238043");
Model.setcreateby ("wh@aishk.com");
Model.setcreatetime ("2016-08-21 14:03:26");
String result = Template.postforobject (URL, model, string.class);
Return ' Result: ' + result;
catch (Exception e) {//Todo:handle Exception e.printstacktrace ();
return E.getmessage (); }} @RequestMapping (value = "/test_map ") @ResponseBody public String Callwsmap () {try {resttemplate template = new Resttemplat
E ();
String url = "Http://localhost:8080/location/map";
map<string, string> map = new hashmap<string, string> ();
Map.put ("CreateBy", "Xiaohong");
String result = Template.postforobject (URL, map, string.class);
Return ' Result: ' + result;
catch (Exception e) {//Todo:handle Exception e.printstacktrace ();
return E.getmessage ();
@RequestMapping (value = "/test_date") @ResponseBody public String callwsdate () {try {
Resttemplate template = new Resttemplate ();
String url = "Http://localhost:8080/location/date";
Return Template.postforobject (URL, new Date (), string.class);
catch (Exception e) {//Todo:handle Exception e.printstacktrace (); return E.getmessage (); }
}
}
Test object, open Browser, Access: http://localhost:8080/project name/test/test_object
Show Results:
result:110.234567 222.238043 xiaoming 2016-08-21 14:03:26
Test map, Open browser, Access: http://localhost:8080/project name/test/test_map
Show Results:
Result:xiaohong
Test date, open browser, Access: http://localhost:8080/project name/test/test_date
Show Results:
Wed Oct 10:19:58 CST 2017