• 我的第一个SpringBoot项目---------->Helloworld


    1  新建一个maven工程;

    2 导入SpringBoot相关的依赖,即修改pom.xml文件配置;

     1 <!--这是Spring Boot的父级依赖,这样当前的项目就是Spring Boot项目了。
     2         spring-boot-starter-parent 是一个特殊的starter,
     3       它用来提供相关的Maven默认依赖。使用它之后,常用的包依赖可以省去version标签。-->
     4     <parent>
     5         <groupId>org.springframework.boot</groupId>
     6         <artifactId>spring-boot-starter-parent</artifactId>
     7         <version>2.2.5.RELEASE</version>
     8         <relativePath/> <!-- lookup parent from repository -->
     9     </parent>
    10      <!--web的场景,自动帮我们引入了web模块开发需要的相关jar包-->
    11     <dependencies>
    12         <dependency>
    13             <groupId>org.springframework.boot</groupId>
    14             <artifactId>spring-boot-starter-web</artifactId>
    15         </dependency>
    16     </dependencies>

    3 编写一个主程序,启动SpringBoot应用

     1 package com.atguigu;
     2 
     3 import org.springframework.boot.SpringApplication;
     4 import org.springframework.boot.autoconfigure.SpringBootApplication;
     5 
     6 @SpringBootApplication//来标注一个主程序类,说明这是一个SpringBoot应用
     7 public class HelloWorldMainApplication {
     8     public static void main(String[] args) {
     9         //spring主程序跑起来
    10         SpringApplication.run(HelloWorldMainApplication.class,args);
    11     }
    12 }

    4 编写相关的Controller,Service

    package com.atguigu.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    @Controller
    public class HelloController {
    
        @ResponseBody
        @RequestMapping("/hello")
        public String hello(){
    
            return "你好世界";
        }
    }

    5运行主程序测试

    6 简化部署,修改pom.xml文件

    <!--打包成一个可以执行的jar包-->
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
  • 相关阅读:
    两个不同于LR和jmeter的性能测试工具
    一个基于集成jenkins的测试平台
    sparkR原理
    Python 出现需要使用fPIC重新编译的问题
    eclipse中使用jython
    R中逻辑运算
    R语言的一些笔记
    Distributed R
    R语言和大数据
    Mysql command line
  • 原文地址:https://www.cnblogs.com/shitulaoma/p/12452343.html
Copyright © 2020-2023  润新知