springboot学习笔记1-构建和启动

第一步:创建项目

1. File->new->project

 2. maven->next

3. 写项目名和路径->finish

4.添加pom文件 只需添加

<parent>和 <dependencies>即可,上面的是自动带出来的

 

<?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>springboot01</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>
    <!-- Inherit defaults from Spring Boot -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
    </parent>
    <!-- Add typical dependencies for a web application -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
</project>

5.写一个主程序和一个controller类 就可以启动项目了

 

package com.temp.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Author: sz
 * @Date: Created in
 */
@RestController // 使用@RestController替代@Controller和@ResponseBody
public class Controller {

    @RequestMapping("/hello")
    public String Hello() {
        return "你好,helloWorld!";
    }
}

package com.temp;

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

/**
 * @Description:
 * @Author: sz
 * @Date: Created in 2022/3/21
 */
@SpringBootApplication
public class MainApplication {

    public static void main(String[] args) {
        // 启动Spring应用
        SpringApplication.run(MainApplication.class,args);
    }
}

 第二步:启动项目

1.启动(run和debug都可以)

 2.启动成功后

 3.执行http://localhost:8080/hello

备注:

1.添加配置文件

server.port=8081

可以修改端口

也可以用yml文件 ,两者区别可以查看如下快速理解yaml(yml)和properties文件_我要大芒果的博客-CSDN博客_yml和yaml文件区别

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孙泽0813

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值