一起学习Spring boot 2.1.X | 第一篇:初识Spring boot

    xiaoxiao2022-07-03  130

    运行展示

    开发环境(小编使用的版本)

    JDK版本 :1.8及以上 (JDK1.8) 开发工具 :Intellij IDEA (IDEA) JAR包 :Maven仓库 (Maven3.6) 服务器 :Tomcat(务必比JDK版本高,小编不在解释(Jar包不用配置、War需要配置))(Springboot内嵌Tomcat)

    步骤

    1.创建Springboot:File-New-Project

    2.创建项目文件结构

    3.POM依赖

    点击Finish; 注:可能Maven中无Jar包需要从仓库下载,需要耐心等待(可以去听首歌)

    4.项目结构

    5.POM.xml

    <?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> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.5.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com</groupId> <artifactId>springboot</artifactId> <version>0.0.1</version> <name>SpringBoot</name> <description>Welcome I am Mu Mo</description> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <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>

    6.小编使用的application.properties文件,项目启动识别两种格式的文件properties和yml文件:

    #Tomcat配置 #address:服务器绑定IP\post:端口号\uriEncoding:编码格式\contextPath:项目名称 #server.address= server.port=80 #server.servlet.contextPath= server.tomcat.uriEncoding=UTF-8

    7.新建TestController.java

    package com.springboot.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class TestController { @RequestMapping("/") public String Test() { return "Springboot!"; } }

    注:@RestController返回JSON数据、@RequestMapping("/路径")

    最新回复(0)