Sring Boot 创建Maven项目(IDEA 2021)

 

 

 

 

 项目名称,存储位置,公司名称等

 

pom.xml

 

 

 

修改 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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>org.example</groupId>
    <artifactId>untitled1</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
        <!-- 选择的Web模块依赖启动器 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

</project>
复制代码

 

新建 Chapter01Application.java

 

 

复制代码
package com.mycompany;


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

@SpringBootApplication
public class Chapter01Application {

    public static void main(String[] args) {
        SpringApplication.run(Chapter01Application.class, args);
    }

}
复制代码

 

新建HelloController.java

 

 

复制代码
package com.mycompany.controller;

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

@RestController     //  该注解为组合注解,等同于Spring中@Controller+@ResponseBody注解
public class HelloController {
    @GetMapping("/hello")  // 该注解等同于Spring框架中@RequestMapping(RequestMethod.GET)注解
    public String hello(){
        return "你好,Spring Boot";
    }
}
复制代码

启动项目

 

 启动之后可以在console中看到以下信息

 

 

在浏览器地址栏输入

http://localhost:8080/hello

 

 

 

 

 

 

 

 

 

IDEA中 Enable Auto-Import 如何取消

File->Settings->Maven->Importing->Import Maven projects automatically (自 IDEA 2020, 2021 之后的版本没有这个了)

 

IntelliJ IDEA 2020.1 brings a small but important update to our Maven and Gradle users. Instead of the old auto-import, there’s now a floating notification in the upper-right part of the editor. Use this notification or a new shortcut (Ctrl+Shift+O for Windows and Linux /Shift+Cmd+I for Mac) to load the changes after you modify the build file. It gets even better: when IntelliJ IDEA detects any changes to the build file made outside the IDE, such as VCS updates, it reloads the related projects automatically.

 

posted @   emanlee  阅读(128)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Blazor Hybrid适配到HarmonyOS系统
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· 解决跨域问题的这6种方案,真香!
· 一套基于 Material Design 规范实现的 Blazor 和 Razor 通用组件库
· 分享4款.NET开源、免费、实用的商城系统
历史上的今天:
2019-04-08 在myeclipse中使用log4j记录日志
2019-04-08 获取Tomcat更详细的日志
2016-04-08 bam/sam格式说明
点击右上角即可分享
微信分享提示