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!

  • 相关阅读:
    每日日报24
    每日日报23
    每日日报22
    链路层:MAC 地址
    应用层:电子邮件
    应用层:HTTP 协议
    应用层:DNS 域名系统
    运输层:TCP 拥塞控制
    运输层:拥塞控制原理
    JAVA学习日记26-0731
  • 原文地址:https://www.cnblogs.com/zou-rong/p/12553446.html
Copyright © 2011-2022 走看看