11.3 编写实例代码
2018-08-14 15:05 更新
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. 尽管这儿没有太多代码, 但是很多代码在进行中。 在接下来的几节中,我们将逐步了解重要的部分。
以上内容是否对您有帮助:
更多建议: