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: 為了完成應用程序, 需要創(chuàng)建一個Java文件。 默認情況下, Maven從src/main/java(目錄)下編譯源碼, 因此需要創(chuàng)建那文件夾結構,然后添加一個名叫src/main/java/Example.java的文件, 文件內(nèi)容包含如下代碼:

  1. import org.springframework.boot.*;
  2. import org.springframework.boot.autoconfigure.*;
  3. import org.springframework.web.bind.annotation.*;
  4. @RestController
  5. @EnableAutoConfiguration
  6. public class Example {
  7. @RequestMapping("/")
  8. String home() {
  9. return "Hello World!";
  10. }
  11. public static void main(String[] args) throws Exception {
  12. SpringApplication.run(Example.class, args);
  13. }
  14. }

Although there is not much code here, quite a lot is going on. We step through the important parts in the next few sections. 盡管這兒沒有太多代碼, 但是很多代碼在進行中。 在接下來的幾節(jié)中,我們將逐步了解重要的部分。

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號