使用 Spring 3 来创建 RESTful Web Services
@RequestMapping(method=RequestMethod.POST, value="/employee")public ModelAndView addEmployee(@RequestBody String body) {Source source = new StreamSource(new StringReader(body));Employee e = (Employee) jaxb2Mashaller.unmarshal(source);employeeDS.add(e);return new ModelAndView(XML_VIEW_NAME, "object", e);}@RequestMapping(method=RequestMethod.PUT, value="/employee/{id}")public ModelAndView updateEmployee(@RequestBody String body) {Source source = new StreamSource(new StringReader(body));Employee e = (Employee) jaxb2Mashaller.unmarshal(source);employeeDS.update(e);return new ModelAndView(XML_VIEW_NAME, "object", e);}@RequestMapping(method=RequestMethod.DELETE, value="/employee/{id}")public ModelAndView removeEmployee(@PathVariable String id) {employeeDS.remove(Long.parseLong(id));List<Employee> employees = employeeDS.getAll();EmployeeList list = new EmployeeList(employees);return new ModelAndView(XML_VIEW_NAME, "employees", list);}
http://www.ibm.com/developerworks/cn/web/wa-spring3webserv/index.html