Spring boot学习(一)

1、Idea创建项目:

a、选择file-->new—>project,选择 Spring Initializr;

b、默认选择Next,配置自己需要的名字选项;

c、填写完相关内容点Next,选择依赖包,目前只选了一个Web,最后点击完成。

创建完成后的项目结构:

image

主要目录:1、src/main/java ---程序开发及主入口;

              2、src/main/resources ---配置文件

              3、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/getStudentInfo

结果如下:

image

猜你喜欢

转载自www.cnblogs.com/chenking/p/10795741.html
今日推荐