zoukankan      html  css  js  c++  java
  • springBoot基本配置

    Spring Boot 基本配置

    1、新建maven jar工程 使用依赖

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    
    <modelVersion>4.0.0</modelVersion>
    
    <groupId>com.pinyougou</groupId>
    
    <artifactId>springbootdemo-helloworld</artifactId>
    
    <version>0.0.1-SNAPSHOT</version>
    
    <!--spring boot 项目必须继承spring boot 父工程 -->
    
    <parent>
    
    <artifactId>spring-boot-starter-parent</artifactId>
    
    <groupId>org.springframework.boot</groupId>
    
    <version>1.5.6.RELEASE</version>
    
    </parent>
    
    <dependencies>
    
    <!--使用spring boot 开发web项目的基础依赖 -->
    
    <dependency>
    
    <groupId>org.springframework.boot</groupId>
    
    <artifactId>spring-boot-starter-web</artifactId>
    
    </dependency>
    
    </dependencies>
    
    </project>

    2、新建启动类

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

    3、启动效果

     

    4、访问

     

    5、添加controller

    package com.springboot.controller;
    
     
    
    import org.springframework.web.bind.annotation.RequestMapping;
    
    import org.springframework.web.bind.annotation.RestController;
    
     
    
    @RestController
    
    public class HelloController {
    
     
    
    @RequestMapping("/hello")
    
    public String hello() {
    
    return "spring boot is so easy to learn!";
    
    }
    
    }

    6、重新启动

     

    7、访问

      

  • 相关阅读:
    四种数据库随机获取10条数据的方法
    古诗词
    一份 Spring Boot 项目搭建模板
    2020年只剩两个月,今年你是怎么过的?
    关于使用LocalDateTime进行存储,时间相差比较多的问题。
    项目中常用的19条MySQL优化
    SpringBoot注解大全
    JDK8的LocalDateTime用法
    linux代理上网5分钟搞定
    SQL简单语句作用
  • 原文地址:https://www.cnblogs.com/alexzhang92/p/10405493.html
Copyright © 2011-2022 走看看