包结构说明
在pom.xml下导入依赖
<!-- 依赖 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
<relativePath />
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
在java包下新建一个java类HelloController类
@Controller(只返回页面,显示用)
@RestController(返回JSON格式的数据,基本都使用这种注解)
@RequestMapping(RequestMapping具体详解)
启动方式
public static void main(String[] args){
SpringApplication.run(HelloController.class,args);
}
新建一个Application类(注意:这个类要和所启动类在同一包下,否则需要添加@ComponentScan注解,并且指定其所要指向的包的类。)
添加@SpringBootApplication注解,然后添加main方法(默认扫描当前启动类所在的包里的对象)
原文:https://www.cnblogs.com/Jidust/p/15073519.html