亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

SpringBoot 1.4.2 入門程序

標簽:
Java

1 新建maven工程,在pom.xml中添加以下代码:

<!-- 添加父依赖 -->
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.2.RELEASE</version>
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <!-- 指定jdk的版本 -->
    <java.version>1.8</java.version>
</properties>

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

 <!-- 添加插件 -->
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

2 编写第一个SpringBoot应用程序

在src/main/java 目录下 新建包 com.ljg.springboot,并在该包中创建App.java文件,代码如下:

/**
* @RestController SpringMVC Rest API 注解
* @EnableAutoConfiguration SpringBoot 注解
*/
@RestController
@EnableAutoConfiguration
public class App {
    // hello 方法
    @RequestMapping("/hello")
    String hello() {
        return "Hello World!";
    }
    // 应用程序主方法
    public static void main(String[] args) {
        // 主程序入口
        SpringApplication.run(App.class, args);
    }
}

3 运行程序

在工程名或pom.xml上右键-->Run As --> Maven build --> Goals 中输入 spring-boot:run --> Run 运行程序,控制台打印

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.2.RELEASE)

表示程序成功启动, 在浏览器输入:http://localhost:8080/hello
在页面上输出:
Hello World!

點擊查看更多內容
3人點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
JAVA開發工程師
手記
粉絲
6
獲贊與收藏
37

關注作者,訂閱最新文章

閱讀免費教程

感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消