• SpringBoot: 1.创建第一个SpringBoot项目(转)


     

     

    一、新建项目

    二、打开项目的pom文件,在里面添加maven依赖

    复制代码
     1 <!--springboot项目依赖的父项目-->
     2     <parent>
     3         <groupId>org.springframework.boot</groupId>
     4         <artifactId>spring-boot-starter-parent</artifactId>
     5         <version>2.0.0.RELEASE</version>
     6     </parent>
     7 
     8     <!--注入springboot启动器-->
     9     <dependencies>
    10         <dependency>
    11             <groupId>org.springframework.boot</groupId>
    12             <artifactId>spring-boot-starter-web</artifactId>
    13         </dependency>
    14     </dependencies>
    复制代码

    所谓的 springBoot 启动器其实就是一些 jar 包的集合。SprigBoot 一共提供 44 启动器。

    例如:
    4.1 spring-boot-starter-web
    支持全栈式的 web 开发,包括了 romcat 和 springMVC 等 jar
    4.2 spring-boot-starter-jdbc
    支持 spring 以 jdbc 方式操作数据库的 jar 包的集合
    4.3 spring-boot-starter-redis
    支持 redis 键值存储的数据库操作

    三、新建springboot的启动类Application

    package com.cccuu;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    /*******************************************
     * springboot的引导类
     * @Package com.cccuu
     * @Author duan
     * @Date 2019/1/4 19:18
     * @Version V1.0
     *******************************************/
    @SpringBootApplication  //表示当前类是springboot的启动类
    @EnableAutoConfiguration //表示当前类是springboot的启动类
    @ServletComponentScan   //在springboot启动时,会扫描@WebServlet,并将该类实例化
    @ComponentScan //注解组件扫描
    public class Application {
    
        public static void  main(String[] args){
            SpringApplication.run(Application.class,args);
        }
    }

    四:新建一个controller

    复制代码
     1 package com.cccuu.controller;
     2 
     3 import org.springframework.web.bind.annotation.RequestMapping;
     4 import org.springframework.web.bind.annotation.RestController;
     5 
     6 /*******************************************
     7  *
     8  * @Package com.cccuu.controller
     9  * @Author duan
    10  * @Date 2019/1/4 19:34
    11  * @Version V1.0
    12  *******************************************/
    13 @RestController
    14 @RequestMapping("/springboot")
    15 public class HelloWorldController {
    16 
    17     @RequestMapping("/hello")
    18     public String sayHello(){
    19         return "hello world";
    20     }
    21 }
    复制代码

     五:运行启动类Application的main方法

    在浏览器上进行访问

    注意:

    1:启动类Application扫描包时扫描其所在的包以及该包下的所有子包

    转自:天涯浪子心

  • 相关阅读:
    PsySH——PHP交互式控制台
    PHP通过ssh或socks5读取远程服务器的mysql数据库
    构建:vue项目配置后端接口服务信息
    module.exports用法
    PhpStorm连接服务器,开始自动上传功能
    JavaScript Array.some()方法用法
    vue-router query和params传参(接收参数),$router、$route的区别
    ES6箭头函数(Arrow Functions)
    工作中常用到的ES6语法
    VueJs2.0建议学习路线
  • 原文地址:https://www.cnblogs.com/kuangzhisen/p/10427070.html
Copyright © 2020-2023  润新知