zoukankan      html  css  js  c++  java
  • SpringBoot-环境搭建

    SpringBoot-环境搭建

    标签(空格分隔): java,SpringBoot

    1.创建Maven工程

    spring-入门搭建-1.png

    2.编写pom文件

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>
    </parent>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.6</version>
        </dependency>
    
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.12</version>
        </dependency>
    </dependencies>
    

    3.编写SpringBoot引导类

    package com.itheima;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class MySpringBootApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(MySpringBootApplication.class, args);
        }
    }
    

    4.编写Controller

    package com.itheima.web;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    import javax.sql.DataSource;
    
    @Controller
    public class HelloController {
    
    
        @Autowired
        private DataSource dataSource;
    
        @GetMapping("/hello")
        @ResponseBody
        public String hello() {
            return "hello spring boot";
        }
    }
    

    5.运行测试

    springboot-运行.png

    springboot-控制台.png

    springboot-测试.png

    6.注意事项

    1. JDK版本配置
    2. Maven仓库配置
  • 相关阅读:
    JS中的call()和apply()方法和bind()
    reactjs入门到实战(十)----one-first_app
    49-Reverse Linked List II
    48-Merge Sorted Array
    47-Generate Parentheses
    46.Valid Parentheses
    45-Letter Combinations of a Phone Number
    44-Count and Say
    43-Reverse Nodes in k-Group
    42-Remove Nth Node From End of List
  • 原文地址:https://www.cnblogs.com/yanweifeng/p/13377195.html
Copyright © 2011-2022 走看看