• [Spring Boot ] Creating the Spring Boot Project : Demo: Creating a REST Controller


    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();
        }
    }
  • 相关阅读:
    JTA
    JPA
    深度优先搜索与广度优先搜索
    http和https区别
    数据库系统阶段特点
    Java中定义和声明
    java之集合ArrayList实例
    java实例之商品库
    java之封装
    java之类和对象
  • 原文地址:https://www.cnblogs.com/Answer1215/p/9609995.html
Copyright © 2020-2023  润新知