IDEA创建SpringBoot项目输出hello world——新手教程(1)

  1. idea新建项目

在这里插入图片描述

  1. 点击next
    在这里插入图片描述
  2. 点击next
    在这里插入图片描述
  3. 点击next
    在这里插入图片描述
  4. 点击finish,看是否和我生成的一样
    在这里插入图片描述
  5. 新建web入口类
    在这里插入图片描述
  6. 配置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.1.7.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.shaotianyou</groupId>
    <artifactId>springboot-first-project</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springboot-first-project</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.0</version>
        </dependency>

        <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>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.25</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

  1. 配置aplication.properties文件
spring.datasource.url=jdbc:mysql://localhost:3306/schooltao?useUnicode=true&zeroDateTimeBehavior=convertToNull&autoReconnect=true
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  1. HelloWorld.java
package com.shaotianyou.springbootfirstproject;


import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Component
@RequestMapping("/springboot")
public class HelloWorld {

    @RequestMapping(value = "hello",method = RequestMethod.GET)
    public String sayHello(){
        return "Hello";
    }
}

启动项目
在这里插入图片描述最后在地址栏上输入localhost:8080/springboot/hello就能够看到方法中返回的字符串

发布了93 篇原创文章 · 获赞 26 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_38261445/article/details/100176900