前置条件

1、安装jdk

2、安装maven

3、能够上网

 

新建springboot-helloworld工程

使用idea新建

第一步:打开idea,点击create new project

 springboot-helloworld

 

第二步:如下图所示,在左列中选择Spring initializer,右侧选择安装的jdk,然后点击next

 springboot-helloworld

 

第三步:按下图所示填写项目信息

 springboot-helloworld

 

 

第四步:选择项目相关依赖

 springboot-helloworld

 

 

第五步:填写项目名称、选择项目保存路径,点击finish

 springboot-helloworld

 

http://start.spring.io/网址在线新建

       第一步:在浏览器中打开http://start.spring.io/网址

 

       第二步:按如图所示填写如下信息

 springboot-helloworld

 

  第三步:将生成的项目导入idea

 

 

项目目录结构简介

 springboot-helloworld

 

 

HelloWorld案例

新建HelloWorldController

package com.lnjecit.springboothelloworld.controller;

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

/**
 * @author
 * @create 2018-04-16 16:06
 **/
@RequestMapping("/helloWorld")
@RestController
public class HelloWorldController {

    @RequestMapping("/sayHello")
    public String sayHello(@RequestParam("name") String name) {
        return "Hi, " + name;
    }
}

 

  

 

项目启动方式

1、运行SpringbootHelloworldApplication类的main方法

2、在IDEA的Terminal环境下运行mvn spring-boot:run命令

springboot-helloworld

 

3、以jar包方式运行

第一步:先运行clean package -Dmaven.test.skip=true命令,在target目录下生成springboot-helloworld-0.0.1-SNAPSHOT.jar

springboot-helloworld

 

第二步:在Terminal环境下,先切换到springboot-helloworld项目的target目录下,然后运行java -jar springboot-helloworld-0.0.1-SNAPSHOT.jar,端口号默认为8080

jspringboot-helloworld

 

 

如果出现如下信息,说明启动成功。

springboot-helloworld

测试

在浏览器中输入http://localhost:8080/helloWorld/sayHello?name=李寻欢,得到如下结果。

springboot-helloworld

 

相关文章:

  • 2021-10-18
  • 2021-07-05
  • 2021-04-16
  • 2021-12-22
  • 2021-05-25
  • 2021-10-23
  • 2022-01-29
猜你喜欢
  • 2021-06-01
  • 2021-08-10
  • 2021-09-03
  • 2021-04-24
  • 2021-12-14
  • 2021-12-24
相关资源
相似解决方案