springboot01、基本配置

springboot01、基本配置

springboot简介

Spring Boot 为简化 Spring 应用开发而生,Spring Boot 中的 Boot 一词,即为快速启动的意思。Spring Boot 可以在零配置情况下一键启动,简洁而优雅。

为了让 Spring 开发者痛快到底,Spring 团队做了以下设计:

  • 简化依赖,提供整合的依赖项,告别逐一添加依赖项的烦恼;
  • 简化配置,提供约定俗成的默认配置,告别编写各种配置的繁琐;
  • 简化部署,内置 servlet 容器,开发时一键即运行。可打包为 jar 文件,部署时一行命令即启动;
  • 简化监控,提供简单方便的运行监控方式。

基于以上设计目的,Spring 团队推出了 Spring Boot 。

目录

1、pom.xml

2、项目层次

3、启动文件【com.item/Action.java】

4、controller文件

5、启动测试(数据是跨域的)


1、pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.4.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

2、项目层次

3、启动文件【com.item/Action.java】

package com.item;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Action {
    public static void main(String[] args) {
        SpringApplication.run(Action.class,args);//一定是被@SpringBootApplication标记的类
    }

}

4、controller文件

其中@RestController = @Controller + @ResponseBody;

package com.item.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@CrossOrigin
public class UsersController {

    @GetMapping("GetInfo")
    public Object GetInfo(){
        HashMap<String,Object> map=new HashMap<String,Object>();
        map.put("state",true);
        map.put("msg","成功");
        map.put("result","有一个字符串");
        return map;
    }
}

5、启动测试(数据是跨域的)

访问路径:【http://127.0.0.1:8080/GetInfo

猜你喜欢

转载自blog.csdn.net/feng8403000/article/details/125305811
今日推荐