书接上文⬆⬆⬆
HTTP 是平台
要使用 Web 层次包装您的存储库,您必须使用 Spring MVC。多亏了 Spring Boot,代码基础设施很少。相反,我们可以专注于行动:
nonrest/src/main/java/payroll/EmployeeController.java
package payroll;
import java.util.List;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
class EmployeeController {
private final
本文继续探讨如何利用Spring构建REST服务,重点介绍HTTP接口的实现,包括GET、POST、PUT和DELETE操作。通过EmployeeController展示了如何处理HTTP请求,使用Spring MVC的注解进行路由,并处理HTTP 404异常。文章最后提出虽然服务可以操作数据,但还缺少某些RESTful原则的实现。
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



