Spring-boot入门(一) 使用IDEA创建一个web项目

使用工具:Idea,Maven,jdk1.8
这里安装IDEA和配置Mavn的过程可以参考:https://blog.csdn.net/Phoenix_smf/article/details/81563118
首先使用Idea新建一个基于maven的springBoot项目
这里写图片描述
选择jdk1.8然后是进行一些项目属性的设置和选择
这里写图片描述
然后选择springBoot的版本(建议选择稳定版本),随手导入web项目的依赖包
这里写图片描述

可以看到新建的项目的目录:其中java存放代码,resources下面的application.properties文件时springBoot的配置文件,
然后是测试目录以及maven的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>

    <groupId>girl</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <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>
            </plugin>
        </plugins>
    </build>


</project>

下面我们写一个控制器:

package girl.demo;

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

@RestController
public class HelloController {
    @RequestMapping(value="/hello",method= RequestMethod.GET)
    public String sayHello(){
        return "hello Springboot";
    }
}

然后启动一下项目,浏览器里输入“http://localhost:8080/hello
这里写图片描述
那么基本的项目搭建就完成了,接下来我们可以完善一下,做一些小功能。

猜你喜欢

转载自blog.csdn.net/Phoenix_smf/article/details/81561860