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

相关文章
相关标签/搜索