zoukankan      html  css  js  c++  java
  • SpringBoot--只是入门

    SpringBoot简化了很多的配置,让开发人员只关注开发即可,所以使用的人数很多。

    1.先创建工程后,在pom.xml中添加依赖。为了方便管理依赖,直接添加parent模块进行依赖版本的管理。

     1    <parent>//管理依赖
     2         <groupId>org.springframework.boot</groupId>
     3         <artifactId>spring-boot-starter-parent</artifactId>
     4         <version>2.1.5.RELEASE</version>
     5     </parent>
     6 
     7 //随后添加依赖
     8 
     9     <dependencies>
    10         <dependency>
    11             <groupId>org.springframework.boot</groupId>
    12             <artifactId>spring-boot-starter-web</artifactId>
    13         </dependency>
    14     </dependencies>

    也可以添加对JDK版本的管理

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

    2.添加依赖后在java文件夹内添加SpringBoot启动项Application(注意一定要添加在需要启动的项目外部,不可以与项目同一个文件夹层)

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    
    //springboot工程都有一个启动引导类   这是一个工程的入口类
    @SpringBootApplication  
    public class Application {
        public static void main(String[] args) {
            SpringApplication.run(Application.class,args);
        }
    }

    3创建子文件夹添加测试类

    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    public class Hello {
    
        @GetMapping("hello")//getmapping或requestMapping都可以
        public String hello(){
            return "hello world";
        }
    }

    4.完成编写后启动Application,然后浏览器输入localhost:8080/hello 就可以查看是否成功*(因为Spring-boot-starter-web 的默认服务器端口是8080)

  • 相关阅读:
    57. Insert Interval
    56. Merge Intervals
    55. Jump Game
    54. Spiral Matrix
    52. N-Queens II
    More Effective C++ 条款2 最好使用C++转型操作符
    More Effective C++ 条款1 仔细区别pointers和references
    Python_内置函数之max
    python_超级基础
    python_format格式化输出、while else、逻辑运算符、编码初识
  • 原文地址:https://www.cnblogs.com/j9527/p/13019560.html
Copyright © 2011-2022 走看看