资讯专栏INFORMATION COLUMN

SpringBoot 1024行代码 - Getting Started(一个简单的web应用)

Soarkey / 2387人阅读

摘要:前言本文是行代码系列的第一篇。本文介绍了如何用搭建一个简单的应用。准备工作安装安装具备和的基础知识具体步骤在中加入的引用创建一个程序入口类添加一个的验证程序调用接口返回结果源码

前言

本文是“SpringBoot 1024行代码”系列的第一篇。本文介绍了如何用SpringBoot搭建一个简单的web应用。

准备工作

1 安装jdk1.8
2 安装maven
3 具备Spring和SpringMVC的基础知识

具体步骤 1. 在pom.xml中加入SpringBoot的引用
    

        
            org.springframework.boot
            spring-boot-starter
        

        
            org.springframework.boot
            spring-boot-starter-web
        

    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    
2. 创建一个程序入口类
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);
    }
}
3. 添加一个SpringMVC的controller
package com.example.demo.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoController {

    @RequestMapping("/hello")
    String home() {
        return "Hello World!
";
    }
}
4. 验证程序

调用接口

curl 127.0.0.1:8080/hello

返回结果

Hello World!
源码

https://github.com/gzllol/spr...

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/67864.html

相关文章

  • SpringBoot 1024代码 - 集成Logback

    前言 SpringBoot是一个全家桶,可以方便的集成各种开发工具。日志框架是一个在线应用必需的,本文介绍了当前主流日志框架Logback与SpringBoot的集成方法 准备工作 完成SpringBoot 1024行代码 - Getting Started(一个简单的web应用) 具体步骤 1. 添加Logback的配置文件logback-springboot.xml 其中文件名需要为logba...

    dailybird 评论0 收藏0
  • SpringBoot 1024代码 - 系统监控工具 Actuator简介

    摘要:前言在生产环境中,我们比较关心任意时刻一个的运行情况。调用接口返回结果我们猜测这个应该是表示应用程序正在正常运行。调用接口返回结果似乎什么都没发生,没关系,我们继续进行。我们继续试了上文列举的若干接口,发现大部分返回结果都是未授权。 前言 在生产环境中,我们比较关心任意时刻一个JVM的运行情况。SpringBoot为我们提供了一个方便的功能模块Actuator。只要简单几步就可以为我们...

    darkerXi 评论0 收藏0
  • SpringBoot学习笔记:Getting Started构建第一个Spring Boot工程

    摘要:本文参考官方文档部分特定版本如版本官方文档地址注本文基于构建话说在上已经有多颗星了,足见火爆程度简介以下介绍引自创建独立的应用程序直接嵌入,或无需部署文件提供自己的入门来简化你的配置尽可能自动配置提供生产就绪功能,如指标,运行 本文参考 Spring Boot官方文档 Part II. Getting Started部分特定版本如1.5.10.RELEASE版本官方文档地址:https...

    Drummor 评论0 收藏0
  • SpringBoot非官方教程 | 第二十篇: 处理表单提交

    摘要:创建工程涉及了,加上和的起步依赖。创建实体代码清单如下创建页面展示层启动工程,访问点击参考资料源码下载 这篇文件主要介绍通过springboot 去创建和提交一个表单。 创建工程 涉及了 web,加上spring-boot-starter-web和spring-boot-starter-thymeleaf的起步依赖。 org.springf...

    impig33 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<