SpingBoot(一)——HelloWord

项目搭建

新建项目

选择版本号(若没有要用的版本可进入工程自行修改)

选择所需木块(会在初始化项目时自动下载所用jar包,也可以不选自行添加)

DevTools 热部署
Security 权限管理
Lombok  get/set方法
Configuration Processor  配置文件注解提示
Validation  字符串验证

完整的目录结构

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<!--父依赖必须 表明是个Springboot项目有它管理本号--->
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.3.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.springboot</groupId>
	<artifactId>init</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>init</name>
	<description>Demo project for Spring Boot</description>
	<properties>
		<java.version>1.8</java.version>
	</properties>
	<dependencies>
        <!--web模块启动器-->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
         <!--测试包-->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>
</project>

至此完毕;跟SSM搭建项目相比可以明显感受到:

1.创建过程简洁简单

2.没有繁杂的xml文件配置

3.MVEN配置更省心 ,starter大大简化jar包的引入

4.内置tomcat,不用配置即可启动

package com.springboot.init.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("/init")
public class initController {
    @GetMapping()
    public String init(){
        return "hello SpringBoot!";
    }
}

启动InitApplication访问 http://localhost:8080/init

版本控制

此项目中web场景启动器的引入与SSM中jar包相比并没有指明版本号,原因在于:

   每个springboot项目都有个必须的父项目
   <parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.3.RELEASE</version>
		<relativePath/>
	</parent>
	而父项目依赖于
  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath>../../spring-boot-dependencies</relativePath>
    </parent>
	spring-boot-dependencies中管理者几乎所有常用的场景的启动器的版本号;因此在使用到web场景时直接导入启动器而无需再自行管理版本号(当然也有一些并没用在版本管理中就需要指明版本号)

GitHub项目地址

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值