一、创建springboot项目
二、在pom.xml文件中添加springboot运行包
<!-- 集成springboot父类工程 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>
<dependencies>
<!-- springboot的web功能依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
三、创建springboot启动类及springboot客户端获取数据
package com.lueacy.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class LueacySpringbootApplication {
public static void main(String[] args) {
SpringApplication.run(LueacySpringbootApplication.class, args);
}
}
package com.lueacy.springboot.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloWorldController {
@RequestMapping("/")
public String index() {
return "HELLO WORLD";
}
}
四、运行结果
五、代码讲解:
1.springboot内置了tomcat,默认端口8080,项目名为'/'
2.springboot启动类(@SpringBootApplication所在的类)自动扫描该启动类所在的包及所有子包下的类,添加到容器中,所以一般来说,没有必要的话,都会将需要扫描的类放在启动类所在的包及其子包下。如果有例外情况可以使用@Component或@ComponentScan注解进行定向扫描。
(举一反三,@Mapper,@MapperScan)
[email protected] == @Controller + (该类下所有的方法)@ResponseBody