springboot 入门-Idea创建helloworld工程

一:准备环境

1.JDK环境:JDK1.8

开发环境:IDEA2018.3

二:创建IDEA项目工程

三:HelloWorld实例

  1. 目录结构:

  2. 编写controllor代码

    package com.controller;
    
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @EnableAutoConfiguration
    public class helloController {
    
        @RequestMapping("/hello")
        private String hello(){
            return "Hello World!";
        }
    }
    
  3. 注意!!!

    DemoApplication 一定要放在包的最外层!!!否则出现以下错误!!!
    

四:项目启动

两种方式:

  1. application启动
  2. IDEA工具栏启动

五:测试helloworld

打开浏览器输入:   http://localhost:8080/hello  

猜你喜欢

转载自blog.csdn.net/weixin_41925975/article/details/85318564
今日推荐