Spring Boot快速入门(一):Hello Spring Boot

1、准备工做

java环境:jdk 1.8
开发工具:ideahtml

2、建立项目

打开ideajava

图片描述

点击Create New Projectgit

图片描述

选择Spring Initializr,Nextgithub

图片描述

Group.Artifact = 你的包名
type:我的喜欢选择gradle,默认的maven也能够
Nextweb

图片描述

选择web
Nextspring

图片描述

选择工程目录
Finish浏览器

图片描述

若是目录不存在,Idea将帮你建立,点击ok就行app

图片描述

若是没有下载过gradle,默认选择就行,点ok
若是想使用已存在的gradle选择Use local gradle distributionmaven

图片描述

等待右下角(红圈部分)下载完成ide

图片描述

添加HelloCtrl类
添加以下代码

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller//这是一个控制器
public class HelloCtrl
{
    @RequestMapping("/")//将地址映射到 / 即访问http://localhost:8080 就能够进入这个方法
    @ResponseBody//返回数据,若是不添加该注解将在resources/templates下寻找与之对应的html模版
    public String hello()
    {
        return "hello spring boot";
    }
}

3、运行

图片描述

点击右上角启动
若是没有启动可点
点击HelloSpringBootApplication左边的启动箭头便可启动

图片描述

启动成功控制的打印以下图所示内容

图片描述

打开浏览器,http://localhost:8080

图片描述

出现hello spring boot字样则成功
源码地址:https://github.com/LieRabbit/...
原文地址:http://lierabbit.cn/2018/01/1...

相关文章
相关标签/搜索