pom文件引入依赖
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.3.RELEASE</version> </parent> <dependencies> <!—SpringBoot web 组件 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> |
spring-boot-starter-parent作用 在pom.xml中引入spring-boot-start-parent,spring官方的解释叫什么stater poms,它可以提供dependency management,也就是说依赖管理,引入以后在申明其它dependency的时候就不需要version了,后面可以看到。 spring-boot-starter-web作用 springweb 核心组件 spring-boot-maven-plugin作用 如果我们要直接Main启动spring,那么以下plugin必须要添加,否则是无法启动的。如果使用maven 的spring-boot:run的话是不需要此配置的。(我在测试的时候,如果不配置下面的plugin也是直接在Main中运行的。)
|
spring boot启动类
package com.fwf; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication @EnableScheduling//在Spring Boot的主类中加入@EnableScheduling注解,启用定时任务的配置 @MapperScan({"com.fwf.mapper"})//将项目中对应的mapper类的路径加进来就可以了 @ComponentScan(basePackages = "com.fwf.controller") public class GirlApplication { public static void main(String[] args) { SpringApplication.run(GirlApplication.class, args); } } |
@RestController
在上加上RestController 表示修饰该Controller所有的方法返回JSON格式,直接可以编写 Restful接口,相当于Controller和@ResponseBody |
注解:作用在于让 Spring Boot 根据应用所声明的依赖来对 Spring 框架进行自动配置 |
SpringApplication.run(HelloController.class, args)
标识为启动类 |
@ComponentScan(basePackages ="com.fwf.controller")
控制器扫包范围 |
@EnableScheduling
在Spring Boot的主类中加入@EnableScheduling注解,启用定时任务的配置 |
@MapperScan({"com.fwf.mapper"})
将项目中对应的mapper类的路径加进来就可以了 |