首页 > 编程语言 > 详细

1.开始Springboot 基本配置和helloworld

时间:2019-09-27 09:36:31      阅读:76      评论:0      收藏:0      [点我收藏+]

1 pom.xml

首先引入两个xml节点

   <!--这里面继承了springboot很多相关依赖-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.6.RELEASE</version>
    </parent>

    <!--web相关依赖-->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

这两个节点的作用如注释

创建一个控制器 com.superman.springboot.Controller.HelloController

内容如下:

package com.superman.springboot.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 "hello world";
    }
}

注意上述代码中的特性 @Controller @ResponseBody  @RequestMapping

然后要创建一个网站启动的引导类

取名(随意):StartApplication

package com.superman.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class StartApplication {
    public static void main(String[] args) {
        SpringApplication.run(StartApplication.class,args);
    }
}

注意特性 SpringBootApplication 和启动方法SpringApplication.run(StartApplication.class,args);

如果要生成jar包

在pom文件中加入节点

<!--可以将当前项目打成jar包进行运行-->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

技术分享图片

 

 就可以生成对应的jar 包 进入jar包所在目录 执行以下dos命令 即可启动程序

技术分享图片

 

1.开始Springboot 基本配置和helloworld

原文:https://www.cnblogs.com/wholeworld/p/11595532.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!