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!

  • 相关阅读:
    Python 更新pip报错:Could not install packages due to an EnvironmentError: [WinError 5] 拒绝访问
    Vs code 配置(1)-win10
    博客园主题--sukura
    log4j
    安装ant问题
    freemarker string= null
    学习随想
    j2ee学习资料收集
    eclipse + marven
    好文mark
  • 原文地址:https://www.cnblogs.com/zou-rong/p/12553446.html
Copyright © 2011-2022 走看看