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:
為了完成應(yīng)用程序, 需要創(chuàng)建一個Java文件。 默認(rèn)情況下, Maven從src/main/java
(目錄)下編譯源碼, 因此需要創(chuàng)建那文件夾結(jié)構(gòu),然后添加一個名叫src/main/java/Example.java
的文件, 文件內(nèi)容包含如下代碼:
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. 盡管這兒沒有太多代碼, 但是很多代碼在進(jìn)行中。 在接下來的幾節(jié)中,我們將逐步了解重要的部分。
更多建議: