当前位置: 代码迷 >> Web前端 >> 使用 Spring 三 来创建 RESTful Web Services
  详细解决方案

使用 Spring 三 来创建 RESTful Web Services

热度:479   发布时间:2013-09-09 20:31:09.0
使用 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
  相关解决方案