Spring Boot快速入门

创建一个maven项目,向浏览器页面打印一句hello world


1.导入坐标

在这里插入图片描述
在这里插入图片描述

2.创建HelloWorldApplication类

在这里插入图片描述

package com.hao.boot;

/**
 * @author:抱着鱼睡觉的喵喵
 * @date:2020/12/12
 * @description:spirngboot第一个应用
 */

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @SpringBootApplication来标注一个主程序类,说明这是一个主程序类
 */
@SpringBootApplication
public class HelloWorldApplication {

    public static void main(String[] args) {
        //Spring应用启动起来
        SpringApplication.run(HelloWorldApplication.class,args);
    }
}

3.创建HelloController前端控制类

package com.hao.boot.controller;

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

/**
 * @author:抱着鱼睡觉的喵喵
 * @date:2020/12/12
 * @description:
 */
@Controller
public class HelloController {

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

4.启动

在这里插入图片描述
5.结果

在这里插入图片描述
6.访问-》http://localhost:8080/hello

在这里插入图片描述


看完这你会感觉Spring Boot的配置文件是真的少;而且从步骤5中的结果可以看到Spring Boot内置了tomcat服务器;假如我们使用Spring和SpringMVC完成这个项目,首先需要导入一系列坐标;然后配置spring和springmvc的核心配置文件以及web.xml,还需要tomcat服务器的配置,打成war包等,我们会发现非常麻烦,而对比下来Spring Boot就非常简便

###我们学习SpringBoot之前需要对Spring等相关的框架有一定的了解;就比如步骤3当中的@Controller、@RequestMapping以及@ReponseBody注解,这些都是SpringMVC当中的基础,所以说Spring相关框架不仅要学,而且要精通





接下来我们打成jar包,在windows中的doc部署

注意点:
1.以下这个插件必须导入在这里插入图片描述
2.第十行必须改成打包成jar(否则打包时会打成war包)
在这里插入图片描述
3.这个第八行<artifactId.>标签中的内容不能包含空格和中文字符(否者打包时会出现process defined的错误)
在这里插入图片描述
步骤

1.点击左下角-》Maven
在这里插入图片描述

在这里插入图片描述
2.打包之后找到jar包所在路径在这里插入图片描述
3.右键jar包-》点击属性-》复制路径
在这里插入图片描述
4. win+r输入cmd打开doc命令行,cd到该目录下
在这里插入图片描述
5.输入dir查看该目录下的文件
在这里插入图片描述
6.输入,然后回车(注意你可以输入java-jar Spring之后直接点击table键,系统会自动帮你补全,这是jar包的名字)在这里插入图片描述
7.启动成功在这里插入图片描述
8.访问http://localhost:8080/hello
在这里插入图片描述
9.最后关掉服务
打开另外一个doc窗口,执行以下操作
在这里插入图片描述


到这里就结束了,希望对你有所帮助

😘😉

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Thecoastlines

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值