spring boot 学习笔记(002) Hello world

来源:互联网 发布:svn 默认端口号 编辑:程序博客网 时间:2024/04/25 13:20

1,在src/main/java下,新建类:

HelloWorld


如下代码:

package springboot;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;  @Controller  @EnableAutoConfiguration  @SpringBootApplicationpublic class HelloWorld {public static void main(String[] args) {//第一个简单的应用,          SpringApplication.run(HelloWorld.class,args);}@RequestMapping("/hello")      @ResponseBody      public String hello(){            return "Hello World";      }  @RequestMapping("/rundemo")      @ResponseBody      public String demo(){            return "This is demo";      }  }


2,右键工程,选择“Run as” / "Maven build ..."

参数  -X clean install


然后 Run


编译通过:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16.605 s
[INFO] Finished at: 2016-06-28T13:41:28+08:00
[INFO] Final Memory: 24M/311M
[INFO] ------------------------------------------------------------------------


3,

对HelloWorld.java 右键,点击“Run as ” "Java Appleation"

就启动了


浏览器里,输入:

http://localhost:8080/rundemo

或者

http://localhost:8080/hello


都能看到效果。



0 0