我有一个要求,需要通过 Spring 和 Hibernate 的 REST Web 服务公开 CRUD 操作。演示是通过 JSF 进行的。如果我能得到一个示例代码,那将会有很大的帮助。
最佳答案
@Controller
@RequestMapping("/foo")
public class FooController {
@Inject private FooService service;
@RequestMapping("/create", method=RequestMethod.PUT)
public void create(@Valid Foo foo) { .. }
@RequestMapping("/retrieve", method=RequestMethod.GET)
public String retrieve(@RequestParam String fooId { .. }
//etc for POST and DELETE
}
(有时人们倾向于跳过请求方法限制,但这样感觉更RESTful)
关于java - 使用 Spring 和 Hibernate 的 REST Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6872965/