zoukankan      html  css  js  c++  java
  • Spring Boot 入门

    一、Spring Boot 入门

    环境约束

    –jdk1.8:Spring Boot 推荐jdk1.7及以上;java version "1.8.0_112"

    –maven4.x:maven 3.3以上版本;Apache Maven 3.3.9

    –IntelliJIDEA2017:IntelliJ IDEA 2017.2.2 x64、STS

    统一环境;

    编写第一HelloWorld程序

     SpringBoot的主程序:

    package com.example.demo;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    @SpringBootApplication
    public class DemoApplication {

    public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
    }
    }
    SpringBoot的Controller的程序:
    package com.example.demo.controller;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;

    @ResponseBody
    @Controller
    public class HelloWolrd {
    @RequestMapping("/hello")
    public String hello(){
    return "hello";
    }
    }

    这样我们就可以运行程序了,程序跑起来之后在浏览器中输入LocalHost:8080/hello就可以进行访问了
    下图就是成功后的样子

     

    我的时候要注意一下文件的位置,你建立的Controller只能在DemoApplication 也就是SpringBoot的主程序同一层级或者下一层级,只有这样能执行。

  • 相关阅读:
    MYSQL架构和Innodb存储引擎
    MySQL基础
    ConcurrentHashMap
    线程池
    并发包(JUC)之阻塞队列
    并发包(JUC)之Condition、CountDownLatch
    并发包(JUC)之Lock和AQS
    volatile关键字——数据可见性问题
    对象锁——synchronized关键字
    获取ip
  • 原文地址:https://www.cnblogs.com/xyzmy/p/9769119.html
Copyright © 2011-2022 走看看