Java-Spring-Boot-Initial

Initial project And Hello world

download IntelliJ IDEA

建立一個新的 spring demo

Image

安裝好之後可以建立一個新的 Controller

src -> main -> java -> {packagename} -> web -> HelloController.java

1
2
3
4
5
6
7
8
9
10
11
package com.example.demo.springbootdemo.web;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class HelloController {
@RequestMapping(value="/say", method = RequestMethod.GET)
public String helloGET() {
return "Hello World GET";
}
}

這樣就可以直接新增了一個 http://loclahost:8081/api/say 的 api

@RestController 代表這是一個 Restful API class

@RequestMapping("route") 來處理 url route 問題

  • value: route
  • method: method [GET, POST, PUT, PATCH, DELETE]
文章目录
  1. 1. Initial project And Hello world
|