zoukankan      html  css  js  c++  java
  • 第一个springboot程序

    环境准备:

    • java version "1.8.0_181"

    • Maven-3.6.1

    • SpringBoot  最新版

    开发工具:

    • IDEA

    Spring官方提供了非常方便的工具让我们快速构建应用

    https://start.spring.io/

     创建项目:

    方式一:使用官方创建

    1. 进入官方网址 https://start.spring.io/
    2. 填写项目所需的信息,选择依赖 springWeb
    3. 点击左下角生成项目,并且下载
    4. 解压项目,在Idea中以maven项目导入
    5. 等待下载依赖

    方式二:使用 IDEA创建

    1. 创建项目,选择spring initalizr
    2. 填写项目所需的信息
    3. 勾选web初始化组件
    4. 等待构建

    分析一下项目的结构:

    分析pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <!--父依赖-->
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.4.3</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>com.example</groupId>
        <artifactId>demo</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>helloworld</name>
        <description>Demo project for Spring Boot</description>
        <properties>
            <java.version>1.8</java.version>
        </properties>
        <dependencies>
            <dependency>
                <!--web场景启动器 其中包括
                spring-boot-starter
                spring-boot-starter-json
                tomcat
                spring-web
                spring-webmvc
                -->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <!--springboot 单元测试-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
        <!--打包插件-->
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>

    编写一个http接口

    1. 在主程序的同级目录,新建controller包
    2. 在包中新建类
    @RestController
    public class HelloController {
        @RequestMapping("/hello")
        public String hello(){
            return "hello,world!";
        }
    }

    运行主程序

  • 相关阅读:
    Windows 下ftp命令基本使用
    Oracle学习笔记:oracle和serverver在过程sql中通过select对变量进行赋值的区别
    分享最新36款高质量免费英文字体
    分享31个漂亮的矢量背景素材
    30个使用大自然元素设计的 Logo 欣赏
    分享5款精美的WordPress免费主题
    分享最新40个很不错的 PSD 资源
    WordPress精美免费主题分享系列之杂志风格篇
    分享25个很棒的网页设计教程和资源网站
    分享50个 CSS3 最佳应用示例
  • 原文地址:https://www.cnblogs.com/IanIan/p/14432110.html
Copyright © 2011-2022 走看看