1.idea新创建一个项目

【spring boot】【idea】100.idea新建一个spring boot项目_maven

 

 

【spring boot】【idea】100.idea新建一个spring boot项目_maven_02

 

 【spring boot】【idea】100.idea新建一个spring boot项目_spring_03

 

 【spring boot】【idea】100.idea新建一个spring boot项目_apache_04

 

 【spring boot】【idea】100.idea新建一个spring boot项目_java_05

 

 【spring boot】【idea】100.idea新建一个spring boot项目_apache_06

 

 

【spring boot】【idea】100.idea新建一个spring boot项目_java_07

 

 

 

 

 

2.setting进入,选择自己的Maven

【spring boot】【idea】100.idea新建一个spring boot项目_xml_08

 

 【spring boot】【idea】100.idea新建一个spring boot项目_java_09

 

 

 

 

 

3.简单补充一下pom.xml

【spring boot】【idea】100.idea新建一个spring boot项目_spring_10【spring boot】【idea】100.idea新建一个spring boot项目_spring_11
<?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.9.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.sxd</groupId>
    <artifactId>firstdad</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>firstdad</name>
    <description>Demo project for Spring Boot</description>

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

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

        <!--jsp页面使用jstl标签-->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

        <!--用于编译jsp-->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </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>
View Code

 

 

4.启动即可

【spring boot】【idea】100.idea新建一个spring boot项目_maven_12

 

 

 

最简单的启动起来了

【spring boot】【idea】100.idea新建一个spring boot项目_java_13

 

 

 

 

5.试着写一个controller访问一下

【spring boot】【idea】100.idea新建一个spring boot项目_java_14

 

 

【spring boot】【idea】100.idea新建一个spring boot项目_spring_10【spring boot】【idea】100.idea新建一个spring boot项目_spring_11
package com.sxd.firstdad.controller;

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

/**
 * @Author: SXD
 * @Description:
 * @Date: create in 2019/10/9 15:37
 */
@RestController
public class FirstController {

    @RequestMapping(value = "/myTest",method = {RequestMethod.GET,RequestMethod.POST})
    public String myTest(){
        System.out.println("进入Controller");
        return "访问成功 ";
    }
}
View Code

 

重启后访问:

【spring boot】【idea】100.idea新建一个spring boot项目_maven_17

 

 【spring boot】【idea】100.idea新建一个spring boot项目_spring_18

 

 

 

6.写一个test,运行一下

【spring boot】【idea】100.idea新建一个spring boot项目_apache_19

 

 

 

 

7.打包成jar包运行一下

【spring boot】【idea】100.idea新建一个spring boot项目_maven_20

 

 【spring boot】【idea】100.idea新建一个spring boot项目_apache_21

 

【spring boot】【idea】100.idea新建一个spring boot项目_spring_22

 

 

 【spring boot】【idea】100.idea新建一个spring boot项目_java_23

 

 

 

CMD进入对应目录,

java命令运行:

java -jar firstdad-0.0.1-SNAPSHOT.jar

【spring boot】【idea】100.idea新建一个spring boot项目_maven_24

 

 

 

访问一下:

【spring boot】【idea】100.idea新建一个spring boot项目_java_25