zoukankan      html  css  js  c++  java
  • 【SpringBoot】IDEA使用maven创建第一个SpringBoot项目

    新建一个标准的maven项目,不选择任何模板

    然后在resources文件夹中,新建static文件夹用来存放JS,图片等静态资源。新建templates文件夹用来存放JSP,HTML等。新建资源文件application.properties。这些都使用固定的名称。

    在pom.xml中加入三部分(最新版的可参考官方网站)。

        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.7.RELEASE</version>
        </parent>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>

    新建一个Controller用于测试(SpringMVC的相同的注解,测试路径为localhost:8080/out):

    package com.hj.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    @Controller
    public class MyController {
        @RequestMapping("/out")
        @ResponseBody
        public String out(){
            return "success";
        }
    }

    入口类(类名为项目名+Application,红色部分为自己的部分):

    package com.hj;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class myspringbootApplication {
        public static void main(String[] args) {
            SpringApplication.run(myspringbootApplication.class);
    
        }
    }

    在入口类中,右键,选择RUN

    在浏览器中输入测试路径就可以正常访问

  • 相关阅读:
    Codeforces 992C(数学)
    Codeforces 990C (思维)
    Codeforces 989C (构造)
    POJ 1511 Invitation Cards(链式前向星,dij,反向建边)
    Codeforces 1335E2 Three Blocks Palindrome (hard version)(暴力)
    POJ 3273 Monthly Expense(二分)
    POJ 2566 Bound Found(尺取前缀和)
    POJ 1321 棋盘问题(dfs)
    HDU 1506 Largest Rectangle in a Histogram(单调栈)
    POJ 2823 Sliding Window(单调队列)
  • 原文地址:https://www.cnblogs.com/to-red/p/11364380.html
Copyright © 2011-2022 走看看