In Spring boot, define a REST API endpoint is pretty easy.
package com.globomatisc.bike.controllers; import java.util.ArrayList; import java.util.List; import com.globomatisc.bike.models.Bike; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/api/v1/bikes") public class BikesController { @GetMapping public List<Bike> list() { List<Bike> bikes = new ArrayList<>(); return bikes; } @PostMapping @ResponseStatus(HttpStatus.OK) public void create(@RequestBody Bike bike) { } @GetMapping("/{id}") public Bike get(@PathVariable("id") long id) { return new Bike(); } }
原文地址:https://www.cnblogs.com/Answer1215/p/9609995.html
时间: 2024-11-08 15:44:24