zoukankan      html  css  js  c++  java
  • 使用eclipse创建第一个SpringBoot项目

    1、new->maven->maven project,   勾选 Create a simple project,  下一个页面中填入group id(项目组织唯一标识, 如org.apache)和artifact id(应用名,本例子中为

    SpringApplicationDemo),其他默认

    2、配置pom.xml

    <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>com.admin</groupId>
        <artifactId>SpringTest</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>
    
        <name>SpringApplicationDemo</name>
        <description>Demo project for Spring Boot</description>
    
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.0.3.RELEASE</version>
            <relativePath /> <!-- lookup parent from repository -->
        </parent>
    
        <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>

    3、在src/main/java下新建包com.admin,新建类Application,作为程序入口

    @SpringBootApplication
    public class Application {
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    }

    在包下新建类Controller类, 这里新建HelloController类

    @RestController
    public class HelloController {
        
        @RequestMapping("/hello")
        public String test() {
            return "Hello, World!";
        }
    }

    4、在src/main/resources下新建application.properties文件,写上

       server.port=8080

    5、run as -> java application, 等待启动成功(查看console输出),

    6、在浏览器中输入http://localhost:8080/hello

      即可在浏览器中看到HelloController类中hello对应的字符串

  • 相关阅读:
    获取一个日期月的所有日期
    elementUI 日期 周一、周二、周三、周四、周五、周六、周日快捷键
    两个日期之间的天数集合
    数组去重并排序
    日历封装
    <转载> VUE项目中CSS管理
    【转载】Vue项目自动转换 px 为 rem,高保真还原设计图
    HTML5新标签
    pChart图表插件使用
    JavaScript ajax请求
  • 原文地址:https://www.cnblogs.com/wushengwuxi/p/9777320.html
Copyright © 2011-2022 走看看