idea创建springboot工程,编写hello world

不依赖spring提供的模板,自己创建maven工程
按照官网要求:Java 8 、Maven3.5+
第一步:新建maven工程,直接下一步
在这里插入图片描述
根据自己的需要,填写自己的信息,然后finish
在这里插入图片描述

第二步:引入springboot项目需要的pom依赖(注意修改maven配置信息)
在这里插入图片描述
在这里插入图片描述
结合官网信息,需要引入

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>spring-boot-demo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.9</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
</project>

第三步:编写程序,创建MyApplication运行类(官网示例)

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lixl
 * @description
 * @date 2022/1/25
 */
@RestController
@EnableAutoConfiguration
public class MyApplication {
    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }
	// 直接运行main方法
    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }
}

第四步:浏览器输入地址,查看结果 http://localhost:8080
在这里插入图片描述
到此,创建springboot项目结束,运行正常。
需要打包的情况下,在pom文件中,引入打包工具

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值