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!

  • 相关阅读:
    Tomcat修改端口号
    如何修改localhost为自己指定的域名
    Tomcat启动时启动窗口中文乱码问题的解决方案
    Java Web 项目jsp页面无法加载样式
    vue 父传子(通过属性传递)
    vue 父传子 讲解
    表白小爱心
    响应式开发
    组件的重复调用
    reduce
  • 原文地址:https://www.cnblogs.com/zou-rong/p/12553446.html
Copyright © 2011-2022 走看看