首页 > 其他分享 >Spring Boot基础入门

Spring Boot基础入门

时间:2023-01-22 11:22:14浏览次数:55  
标签:web 入门 io Spring Boot https spring

简介

官网:https://spring.io/projects/spring-boot

spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化Spring应用的初始搭建以及开发过程。

在以前的spring项目中,都会面对大量繁琐的配置,使用的时候基本上都是大量的复制黏贴。而Spring Boot 则能让我们在不需要过多的配置下,轻松快速地搭建Spring Web应用,开箱即用,没有代码生成,也无需XML配置,从而快速使用spring框架。

SpringBoot是Spring开发的脚手架。

 

创建一个springboot项目

方式一:

创建项目

 

 空项目

 

输入项目名称

 

选择sdk等

 

配置maven

 

新建模块

 

选择“Spring Initializr”,然后选择jdk版本,另外,默认是从https://start.spring.io拉取代码模板

 

Group和Package改为一样

 

选择starter(SpringBoot提供了许多Starter,也就是启动器,分别对应不同中的应用场景,只要在项目中引入这些starter,相应场景的依赖就会被导入)

web项目,选择"Spring Web"

 

如果要操作数据库,可以选择数据库依赖

 

模块名

 

下面四个可以删除

 

生成的项目

resources下:

  static:保存所有的静态资源,js css images;

  templates:保存所有的模板页面,可以使用模板引擎(freemarker、thymeleaf);

  application.properties:Spring Boot应用的配置文件,可以修改一些默认设置;

 

pom中父工程版本找不到???

 

我们先把父工程的版本换成2.4.5吧

说明:Spring Boot提供了一个名为spring-boot-starter-parent的工程,这个父工程的父工程(spring-boot-dependencies)里面已经对各种常用依赖的版本进行了管理

 

自动导入了很多依赖

 

编写一个控制器:

@RestController = @controller = @ResponseBody

package com.qzcsbj.demo.controller;

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

/**
 * @公众号 : 全栈测试笔记
 * @博客 : www.cnblogs.com/uncleyong
 * @微信 : ren168632201
 * @描述 : <>
 */
@RestController
public class HelloController {
    @RequestMapping(value="hello", method = RequestMethod.GET)
    public String hello(){
        return "hello springboot";
    }
}

  

运行启动类

 

下面日志中可以看到,端口是8080

 

请求:localhost:8080/hello

与之前springmvc相比,少了很多配置,用起来更方便。

 

方式二:在Spring Boot官方Initializer页面在线构建工程再导入到idea中

https://spring.io/projects/spring-boot

 

 

https://start.spring.io/

 

会自动下载生成的项目代码,然后导入idea。

 

【bak】

原文会持续更新,原文地址:https://www.cnblogs.com/uncleyong/p/17064293.html

 

标签:web,入门,io,Spring,Boot,https,spring
From: https://www.cnblogs.com/uncleyong/p/17064293.html

相关文章