SpringBoot之使用IDEA新建Web项目

1. 打开IDEA,点击左上角的File选项,打开菜单选择New,再打开菜单选择Project

2. 选择Spring Initializr,输入或选择项目相关的信息

3. 选择Spring Boot版本以及相应的依赖,并点击右下角的Create按钮进行项目创建

4. 项目创建完成后,点击左上角的File选项,打开菜单选择Settings选项,在弹出的页面中搜索maven,进行maven信息的设置

5. 新建controller包,编写入门程序

package com.springboot.pattern.controller;

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

/**
 * 入门程序
 * @author: yg
 */
@RestController
@RequestMapping("hello")
public class HelloController {

    /**
     * 欢迎信息
     * @return
     */
    @RequestMapping("")
    public String sayHello(){
        return "Hello Spring Boot!";
    }
}

6. 运行程序,打开浏览器进行访问

7. 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.7.10</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.springboot.pattern</groupId>
    <artifactId>springboot_pattern</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springboot_pattern</name>
    <description>springboot_pattern</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <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>
                <version>2.5.14</version>
            </plugin>
        </plugins>
    </build>

</project>

 

posted @ 2023-04-04 11:58  安徒生敲代码  阅读(436)  评论(0编辑  收藏  举报