zoukankan      html  css  js  c++  java
  • SpringBoot入门

    使用idea构建SpringBoot项目

    新建项目-->选择maven(不使用骨架)-->填写groupId和artifactId。。。和创建普通maven工程一致-->finish

    pom.xml添加内容

    <!--SpringBoot启动器作为父工程-->
    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.2.RELEASE</version>
    </parent>
    <!--引入web工程启动器-->
    <dependencies>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    </dependencies>

    编写启动类

    package com.company;

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    //没有配置扫描,默认扫描启动类所在的包
    @SpringBootApplication
    public class BootDemoApplication {

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

    编写测试类,默认端口8080

     package com.company.web;


    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RestController;

    @RestController//作用=@Controller+@ResponseBody
    public class HelloController {

    @GetMapping("/hello")//作用=@RequestMapping(
    method = {RequestMethod.GET})
        public String hello(){
    return "hello Springboot!";
    }
    }

     

    访问http://localhost:8080/hello

      hello Springboot!

  • 相关阅读:
    2019-12-2 异常捕获
    类与类之间的6种关系
    关键字与理解
    this与super的语法比较
    单继承与多继承对比
    为什么javaBean要有get/set方法的设计
    多态在面向对象中的意义以及带来的好处
    十四、线程设计
    十三、窗口设计
    十二、SWING界面设计
  • 原文地址:https://www.cnblogs.com/zou-rong/p/12553446.html
Copyright © 2011-2022 走看看