使用springboot写出hello world

一、springboot简介

Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。通过这种方式,Spring Boot致力于在蓬勃发展的快速应用开发领域(rapid application development)成为领导者。

二、创建项目

创建一个spring initializr的项目,选择1.8的jdk, 网址就可以选择default 项目名在artifact更改,jdk版本改为8 web里选择springweb 项目架构如下: 只需增加一个controller文件,其他都是自动生成的,controller.Java文件如下:

package hellowweb.demo;

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

@RestController
public class controller {
          
   
    @ResponseBody
    @RequestMapping("/hello")
    public String hello(){
          
   
        return "Hello World!";
    }
}

三、运行结果

运行结果如下图

四、总结

用springboot写东西,先创建一个spring initializr项目,再选择web里的spring web,然后在 有@RestController的这个类里进行操作,@的注解不能缺。

经验分享 程序员 微信小程序 职场和发展