码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-09-08 18:58:21      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:ota   bind   variable   pos   create   tco   ram   spring   end   

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();
    }
}

 

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

标签:ota   bind   variable   pos   create   tco   ram   spring   end   

原文地址:https://www.cnblogs.com/Answer1215/p/9609995.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!