【spring boot】【idea】100.idea新建一個spring boot項目

 

1.idea新建立一個項目

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2.setting進入,選擇本身的Maven

 

 

 

 

 

 

 

3.簡單補充一下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.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.啓動便可

 

 

 

最簡單的啓動起來了java

 

 

 

 

5.試着寫一個controller訪問一下

 

 

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

 

重啓後訪問:web

 

 

 

 

 

6.寫一個test,運行一下

 

 

 

 

7.打包成jar包運行一下

 

 

 

 

 

 

 

 

 

CMD進入對應目錄,spring

java命令運行:apache

java -jar firstdad-0.0.1-SNAPSHOT.jar

 

 

 

訪問一下:tomcat

相關文章
相關標籤/搜索