codecamp

11.3 编写实例代码

To finish our application, we need to create a single Java file. By default, Maven compiles sources from src/main/java, so you need to create that folder structure and then add a file named src/main/java/Example.java to contain the following code: 为了完成应用程序, 需要创建一个Java文件。 默认情况下, Maven从src/main/java(目录)下编译源码, 因此需要创建那文件夹结构,然后添加一个名叫src/main/java/Example.java的文件, 文件内容包含如下代码:

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


@RestController
@EnableAutoConfiguration
public class Example {


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


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


}

Although there is not much code here, quite a lot is going on. We step through the important parts in the next few sections. 尽管这儿没有太多代码, 但是很多代码在进行中。 在接下来的几节中,我们将逐步了解重要的部分。

11.1 创建POM
11.3.2 @EnableAutoConfiguration注解
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

I. SpringBoot文档

1.关于文档

2.获得帮助

3.初始学习步骤

4.工作中使用SpringBoot

5.学习Spring Boot新特性

6.投入生产

7.深入学习

II. 入门指南

8. Spring Boot介绍

9. 系统必要条件

9.1. 支持的Servlet容器

10. Spring Boot安装

10.1. 安装说明(开发人员)

10.1.1 Maven安装

10.1.2 Gradle Installation (空)

10.2. Installing the Spring Boot CLI (空)

10.3. Upgrading from an Earlier Version of Spring Boot (空)

11. 开发第一个Spring Boot应用程序

11.1 创建POM

11.2 添加 Classpath 依赖

11.3 编写实例代码

11.3.1 @RestController和@RequestMapping注解

11.3.2 @EnableAutoConfiguration注解

11.3.3 “main”方法

11.4 运行实例程序

11.5 创建可执行程序(Executable Jar)

12. 接下来阅读什么

III. 使用Spring Boot (空)

13. Build Systems(空)

13.2 Maven(空)

13.2.2 Using Spring Boot without the Parent POM(空)

13.5 Starters(空)

IV. Spring Boot新特性 (空)

V. Actuator执行器 (空)

VI. 部署Spring Boot Applications (空)

VII. Spring Boot CLI (空)

VIII. 构建工具插件(空)

68. Spring Boot Maven Plugin(空)

IX. ‘How-to’guides(空)

X. 附录 (空)

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }