专注于 JetBrains IDEA 全家桶,永久激活,教程
持续更新 PyCharm,IDEA,WebStorm,PhpStorm,DataGrip,RubyMine,CLion,AppCode 永久激活教程

SpringBoot 笔记 二:搭建自己的第一个SpringBoot程序

声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅。

一、根据官网手工搭建(http://projects.spring.io/spring-boot/#quick-start)

1、新建一个maven工程springbootfirst

71_1.png

2、 如果要想开发 SpringBoot 程序只需要按照官方给出的要求配置一个父 pom (spring-boot-starter-parent)和添加web开发的支持(spring-boot-starter-web)即可。

 <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>

   <groupId>com.study.springboot</groupId>
   <artifactId>springbootfirst</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>jar</packaging>

   <name>springbootfirst</name>
   <url>http://maven.apache.org</url>

   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <jdk.version>1.8</jdk.version>
   </properties>

     <!--想开发 SpringBoot 程序只需要按照官方给出的要求配置一个父 pom 即可。  -->
     <parent>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-parent</artifactId>
         <version>1.5.4.RELEASE</version>
     </parent>

   <dependencies>

     <!--添加web开发的支持  -->
     <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
     </dependency>

   </dependencies>

   <build>
         <finalName>springbootfirst</finalName>
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <configuration>
                     <source>${jdk.version}</source><!-- 源代码使用的开发版本 -->
                     <target>${jdk.version}</target><!-- 需要生成的目标class文件的编译版本 -->
                     <encode>${project.build.sourceEncoding}</encode>
                 </configuration>
             </plugin>
         </plugins>
     </build>

 </project>

3、 编写一个具体的程序SampleController.java

 package com.study.springboot.springbootfirst;

 import org.springframework.boot.*;
 import org.springframework.boot.autoconfigure.*;
 import org.springframework.stereotype.*;
 import org.springframework.web.bind.annotation.*;

 @Controller
 @EnableAutoConfiguration
 public class SampleController {

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

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

4、启动SampleController.java,在浏览器输入http://localhost:8080/即可看到我们使用SpringBoot搭建的第一个web程序成功了,就是这么的快速、简单、方便

71_2.png

二、快速搭建

1、访问http://start.spring.io/

2、选择构建工具Maven Project、Spring Boot版本1.5.11以及一些工程基本信息,点击“Switch to the full version.”java版本选择1.8,可参考下图所示:

71_3.png

3、点击Generate Project下载项目压缩包

4、解压后,使用eclipse,Import -> Existing Maven Projects -> Next ->选择解压后的文件夹-> Finsh,OK done!

来源:https://www.cnblogs.com/leeSmall/category/1185488.html

文章永久链接:https://tech.souyunku.com/13967

未经允许不得转载:搜云库技术团队 » SpringBoot 笔记 二:搭建自己的第一个SpringBoot程序

JetBrains 全家桶,激活、破解、教程

提供 JetBrains 全家桶激活码、注册码、破解补丁下载及详细激活教程,支持 IntelliJ IDEA、PyCharm、WebStorm 等工具的永久激活。无论是破解教程,还是最新激活码,均可免费获得,帮助开发者解决常见激活问题,确保轻松破解并快速使用 JetBrains 软件。获取免费的破解补丁和激活码,快速解决激活难题,全面覆盖 2024/2025 版本!

联系我们联系我们