SpringBoot项目学习:Hello-SpringBoot

初见SpringBoot

一、pom配置

<?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>boot-01-helloworld</artifactId>
    <version>1.0-SNAPSHOmjh T</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.3.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

<!--    打包工具使maven导出jar包-->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

二、配置主程序类

package com.nanjing.boot;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.SpringApplication;
/**
 * 主程序类
 *@SpringBootApplication 这是一个springboot应用
 */
@SpringBootApplication
public class MainApplication {
    
    
    public static void main(String[] args) {
    
    
        SpringApplication.run(MainApplication.class,args);
    }
}

三、配置Controller

package com.nanjing.boot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@ResponseBody
@Controller
public class HelloController {
    
    

    @RequestMapping("/hello")
    public String handle01(){
    
    
    return "Hello , Spring Boot 2!";
    }
}

四、初识application

#修改端口号
server.port=8888

注:另外由于pom中配置了jar文件,可以用maven直接导出整个项目并且在cmd中直接运行

可直接在这里通过cmd运行文件

猜你喜欢

转载自blog.csdn.net/qq_48642405/article/details/121774796