zoukankan      html  css  js  c++  java
  • 一个简单的SpringBoot入门程序

    1. 使用IDEA构建Maven项目

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <project xmlns="http://maven.apache.org/POM/4.0.0"
     3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     5     <modelVersion>4.0.0</modelVersion>
     6 
     7     <groupId>cn.burgundy</groupId>
     8     <artifactId>springboot-cheatsheep</artifactId>
     9     <version>1.0-SNAPSHOT</version>
    10 
    11     <!-- 继承SpringBoot插件 -->
    12     <parent>
    13         <groupId>org.springframework.boot</groupId>
    14         <artifactId>spring-boot-starter-parent</artifactId>
    15         <version>1.3.3.RELEASE</version>
    16     </parent>
    17 
    18     <dependencies>
    19         <!-- 启动springBoot web启动器 -->
    20         <dependency>
    21             <groupId>org.springframework.boot</groupId>
    22             <artifactId>spring-boot-starter-web</artifactId>
    23         </dependency>
    24     </dependencies>
    25 
    26     <build>
    27         <plugins>
    28             <!-- 使用maven启动springboot -->
    29             <plugin>
    30                 <groupId>org.springframework.boot</groupId>
    31                 <artifactId>spring-boot-maven-plugin</artifactId>
    32             </plugin>
    33         </plugins>
    34     </build>
    35 </project>

    2. 创建SpringBoot启动类

     1 /**
     2  * Created by IntelliJ IDEA.
     3  *
     4  * @Auther: ShaoHsiung
     5  * @Date: 2018/8/29 11:11
     6  * @Title: 一个简单的SpringBoot应用
     7  * @Description: SpringBoot启动类
     8  */
     9 @SpringBootApplication
    10 public class HelloApp {
    11     public static void main(String[] args) {
    12         SpringApplication.run(HelloApp.class, args);
    13     }
    14 }

    备注:

    1) @SpringBootApplication

    2) SpringApplication.run(HelloApp.class, args);

    3. 创建第一个Controller

     1 /**
     2  * Created by IntelliJ IDEA.
     3  *
     4  * @Auther: ShaoHsiung
     5  * @Date: 2018/8/29 11:14
     6  * @Title: 一个简单的SpringBoot应用
     7  * @Description: 第一个controller
     8  */
     9 @RestController
    10 public class HelloController {
    11     @RequestMapping(method = RequestMethod.GET, path = "/hello")
    12     public String hello() {
    13         return "Hello SpringBoot";
    14     }
    15 }

    备注:

    1) @RestController: 具备REST API能力, 将每个REST API的返回值自动序列化为JSON格式

    2) @RequestMapping(method = RequestMethod.GET, path = "/hello")

    4. 使用Maven运行SpringBoot程序

    SpringBoot内置服务器

    5. 应用启动成功

     

    查看到下面这些信息, 说明启动成功...

    6. 访问Web应用

  • 相关阅读:
    分享一个关于Cookie做的实验结果
    使用jest进行单元测试
    【转载】为什么单反镜头做不小,镜头越好越重呢?
    【转载】解读手机摄像头
    【转载】2019中国机器视觉产业全景图谱
    【行业】视觉传感器
    图像质量测评
    COM口了解下
    dbus-python的API及示例
    QtDbus的API及示例
  • 原文地址:https://www.cnblogs.com/shaohsiung/p/9553392.html
Copyright © 2011-2022 走看看