• 使用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对应的字符串

  • 相关阅读:
    Nginx优化
    Mysql日常操作
    YUM源
    MySQL5.7安装手册
    自律——可以让我们活的更高级
    javascript中with的用法
    js中所有函数的参数(按值和按引用)都是按值传递的,怎么理解?
    base64编码的图片在网页中显示
    form表单提交没有跨域问题,但ajax提交存在跨域问题
    移动端1px的适配问题
  • 原文地址:https://www.cnblogs.com/wushengwuxi/p/9777320.html
Copyright © 2020-2023  润新知