Spring Boot从入门到熟练-1.入门


一、创建maven项目

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
填写相关id
在这里插入图片描述
在这里插入图片描述

二、引入Spring Boot

1.引入库

在这里插入图片描述

2.创建示例

在这里插入图片描述

代码如下:

package cn.lilinghui.sprintboottest.controller;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@EnableAutoConfiguration
public class Example {

	@RequestMapping("/")
	String home() {
		return "Hello World!";
	}

	public static void main(String[] args) {
		SpringApplication.run(Example.class, args);
	}

}

这里需要注意的注解是RestController、EnableAutoConfiguration、RequestMapping
RestController:表示该类是controller
EnableAutoConfiguration:表示该应用开启自动配置功能
RequestMapping:表示该类的页面转向

三、测试结果

控制台输出


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.3.RELEASE)

2020-09-03 20:31:42.979  INFO 17200 --- [           main] c.l.sprintboottest.controller.Example    : Starting Example on SCD0079 with PID 17200 (C:\Users\llh\workspace\sprintboottest\target\classes started by lilinghui in C:\Users\llh\workspace\sprintboottest)
2020-09-03 20:31:42.983  INFO 17200 --- [           main] c.l.sprintboottest.controller.Example    : No active profile set, falling back to default profiles: default
2020-09-03 20:31:43.937  INFO 17200 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-09-03 20:31:43.950  INFO 17200 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-09-03 20:31:43.950  INFO 17200 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.37]
2020-09-03 20:31:44.044  INFO 17200 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-09-03 20:31:44.044  INFO 17200 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1013 ms
2020-09-03 20:31:44.253  INFO 17200 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-09-03 20:31:44.442  INFO 17200 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2020-09-03 20:31:44.452  INFO 17200 --- [           main] c.l.sprintboottest.controller.Example    : Started Example in 1.87 seconds (JVM running for 2.27)

以下为输出页面
在这里插入图片描述


总结

以上就是今天要讲的内容,本文仅仅简单介绍了spring boot的入门使用,而spring boot提供了大量能使我们快速便捷地处理web的函数和方法。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值