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的主程序同一层级或者下一层级,只有这样能执行。

  • 相关阅读:
    CentOS 6.5 zabbix 3.0.4 乱码问题
    CentOS-6.5安装zabbix 3.0.4
    NFS工作原理及配置文件详解
    CentOS-6.5-NFS部署
    Swift中简单的单例设计
    UITableViewCell实现3D缩放动画
    Swift
    Swift
    [转]Swift编程风格指南
    pch文件出现no such file or directory错误
  • 原文地址:https://www.cnblogs.com/xyzmy/p/9769119.html
Copyright © 2011-2022 走看看