Spring boot學習(一)

一、Idea建立項目:

a、選擇file-->new—>project,選擇 Spring Initializr;java

b、默認選擇Next,配置本身須要的名字選項;web

c、填寫完相關內容點Next,選擇依賴包,目前只選了一個Web,最後點擊完成。spring

建立完成後的項目結構:api

image

主要目錄:一、src/main/java ---程序開發及主入口;瀏覽器

              二、src/main/resources ---配置文件app

              三、src/test/java  ---單元測試單元測試

建立controller文件夾,在文件夾下建立一個控制器,編寫controller內容,測試

image

package com.project.apiproject.controller;

import com.project.apiproject.pojo.Student;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping(value="test")
public class TestController {

    @RequestMapping(value = "getStudentInfo")
    public List<Student> getStudentInfo(){
        Student stu=new Student("一坪海岸線","男",1);
        List<Student> result=new ArrayList<>();
        result.add(stu);
        return  result;
    }
}

啓動主程序,打開瀏覽器訪問:http://localhost:8080/test/getStudentInfospa

結果以下:3d

image

相關文章
相關標籤/搜索