1.2 运行Hello World
我们就在默认生成的 App.java
文件中写上程序员入门必备的 Hello World
。
/**
* Hello world!
*/
public class App {
public static void main(String[] args) {
Blade.me().get("/", (request, response) -> response.text("Hello World")).start(App.class, args);
}
}
运行 main
函数,此时你会在控制台看到这样的输出信息
2017-06-21 00:02:26:630 INFO - [ _(:3」∠)_ ] c.b.s.n.NettyServer | Environment: jdk.version => 1.8.0_101
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
2017-06-21 00:02:26:633 INFO - [ _(:3」∠)_ ] c.b.s.n.NettyServer | Environment: java.io.tmpdir => /var/folders/y7/fdpr6jzx1rs6x0jmty2h6lvw0000gn/T/
2017-06-21 00:02:26:633 INFO - [ _(:3」∠)_ ] c.b.s.n.NettyServer | Environment: user.timezone => Asia/Shanghai
2017-06-21 00:02:26:633 INFO - [ _(:3」∠)_ ] c.b.s.n.NettyServer | Environment: file.encoding => UTF-8
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/
__, _, _, __, __,
|_) | /_\ | \ |_
|_) | , | | |_/ |
~ ~~~ ~ ~ ~ ~~~
:: Blade :: (v2.0.5-Alpha1)
2017-06-21 00:02:26:661 INFO - [ _(:3」∠)_ ] c.b.m.r.RouteMatcher | Add route => GET /
2017-06-21 00:02:26:667 INFO - [ _(:3」∠)_ ] c.b.s.n.NettyServer | ⬢ Register bean: [com.blade.Environment@215fea12]
2017-06-21 00:02:26:866 INFO - [ _(:3」∠)_ ] c.b.s.n.NettyServer | ⬢ Blade initialize successfully, Time elapsed: 252 ms
2017-06-21 00:02:26:866 INFO - [ _(:3」∠)_ ] c.b.s.n.NettyServer | ⬢ Blade start with 0.0.0.0:9000
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
惊喜的看到 Hello World
输出在网页上!