第1章 快速上手 - 1.2 运行Hello World

优质
小牛编辑
128浏览
2023-12-01

我们就在默认生成的 App.java 文件中写上程序员入门必备的 Hello World

  1. /**
  2. * Hello world!
  3. */
  4. public class App {
  5. public static void main(String[] args) {
  6. Blade.me().get("/", (request, response) -> response.text("Hello World")).start(App.class, args);
  7. }
  8. }

运行 main 函数,此时你会在控制台看到这样的输出信息

  1. 2017-06-21 00:02:26:630 INFO - [ _(:3」∠)_ ] c.b.s.n.NettyServer | Environment: jdk.version => 1.8.0_101
  2. 2017-06-21 00:02:26:633 INFO - [ _(:3」∠)_ ] c.b.s.n.NettyServer | Environment: user.dir => /Users/biezhi/Documents/workspace-sts-3.8.3.RELEASE/first-blade-app
  3. 2017-06-21 00:02:26:633 INFO - [ _(:3」∠)_ ] c.b.s.n.NettyServer | Environment: java.io.tmpdir => /var/folders/y7/fdpr6jzx1rs6x0jmty2h6lvw0000gn/T/
  4. 2017-06-21 00:02:26:633 INFO - [ _(:3」∠)_ ] c.b.s.n.NettyServer | Environment: user.timezone => Asia/Shanghai
  5. 2017-06-21 00:02:26:633 INFO - [ _(:3」∠)_ ] c.b.s.n.NettyServer | Environment: file.encoding => UTF-8
  6. 2017-06-21 00:02:26:636 INFO - [ _(:3」∠)_ ] c.b.s.n.NettyServer | Environment: classpath => /Users/biezhi/Documents/workspace-sts-3.8.3.RELEASE/first-blade-app/target/classes/
  7. __, _, _, __, __,
  8. |_) | /_ | |_
  9. |_) | , | | |_/ |
  10. ~ ~~~ ~ ~ ~ ~~~
  11. :: Blade :: (v2.0.5-Alpha1)
  12. 2017-06-21 00:02:26:661 INFO - [ _(:3」∠)_ ] c.b.m.r.RouteMatcher | Add route => GET /
  13. 2017-06-21 00:02:26:667 INFO - [ _(:3」∠)_ ] c.b.s.n.NettyServer | ⬢ Register bean: [com.blade.Environment@215fea12]
  14. 2017-06-21 00:02:26:866 INFO - [ _(:3」∠)_ ] c.b.s.n.NettyServer | ⬢ Blade initialize successfully, Time elapsed: 252 ms
  15. 2017-06-21 00:02:26:866 INFO - [ _(:3」∠)_ ] c.b.s.n.NettyServer | ⬢ Blade start with 0.0.0.0:9000
  16. 2017-06-21 00:02:26:867 INFO - [ _(:3」∠)_ ] c.b.s.n.NettyServer | ⬢ Open your web browser and navigate to http://127.0.0.1:9000 ⚡

我们打开浏览器访问 http://127.0.0.1:9000

1.2 运行Hello World - 图1

惊喜的看到 Hello World 输出在网页上!

1.2 运行Hello World - 图2