第三步:编写controller
/** * *@author:Heweipo *@version 1.00 * */ @Controller @RequestMapping("/resource") public class ResourceController { @Autowired private ResourceService service; @RequestMapping(value="/get/{id}" , method=RequestMethod.GET) public String get(@PathVariable("id") String id , ModelMap model){ model.put("resource", service.getResource(id)); return "resource"; } }第四步:页面请求,获取 Json xml html 三种格式的数据
浏览器请求URL: 浏览器响应结果:{"resource":{"id":"id_111","name":"maven","number":11}} 浏览器响应结果: <resource> <id>id_111</id> <name>maven</name> <number>11</number> </resource>总结:因为刚刚学习,所以只是一个开始,下周贴出全部源码,仅供学习参考。