首页 > 其他分享 >spring boot——通过maven创建一个spring boot项目

spring boot——通过maven创建一个spring boot项目

时间:2023-01-01 11:11:47浏览次数:44  
标签:spring boot springframework maven org import public

1、配置spring  boot的核心启动器;

2、添加starter模块;

 

 

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

    <groupId>org.example</groupId>
    <artifactId>spring_boot</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.4.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

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


</project>

 

 

 

3、创建应用程序的App类(启动类);

package org.example;

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


@SpringBootApplication
public class helloWorldApplication
{

    public static void main(String[] args)
    {

        SpringApplication.run(helloWorldApplication.class, args);

    }
}

 

 

 

 

 

 4、创建一个controller模块,并运行:

package org.example.controller;

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


@Controller
public class HelloController
{

    /*
    http://localhost:8080/hello
     */
    @ResponseBody
    @RequestMapping("/hello")
    public String hello()
    {

        return "Hello World!____________china";
    }


    //http://localhost:8080/123
    @ResponseBody
    @RequestMapping("/123")
    public String home123()
    {
        return "中国您好";
    }



    //http://localhost:8080/1234
    @RequestMapping(value = "/1234",method = RequestMethod.GET)
    @ResponseBody
    public String home1234()
    {
        return "中国您好_123456";
    }
}

 

 

 

 

 

 

 

 

 启动tomcat:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 ===================================================================================================================

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

标签:spring,boot,springframework,maven,org,import,public
From: https://www.cnblogs.com/xiaobaibailongma/p/17017853.html

相关文章