springboot入門(一) helloworld
pom.xml
<!--
spring boot 父節點依賴,引入這個之後相關的引入就不需要添加version配置,spring boot會自動選擇最合适的版本進行添加。
-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
controller HelloController.java
package com.hnust.controller;
import com.hnust.pojo.UserInfo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by xiaojiang on 2017/8/27.
*/
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello() {
return "helloworld";
}
}
啟動類 AppMain.java
package com.hnust;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Created by xiaojiang on 2017/8/27.
*/
@SpringBootApplication
public class AppMain {
public static void main(String[] args) {
/**在main方法進行啟動我們的應用程式*/
SpringApplication.run(AppMain.class);
}
}
運作java類AppMain的main方法,通路路徑:http://localhost:8080/hello 結果圖:

知識點;
1、導入spring-boot-starter-web 就相當于導入了spring的
2、spring的啟動類必須放在所有子包的外層(預定優于配置)
3、注解@RestControlle相當于@[email protected]