Spring Boot项目搭建

  1. 添加依赖 ``` com.qianmi micro-service ${qm.micro.service.version}

org.springframework.boot spring-boot-starter

org.springframework.boot spring-boot-starter-web


2. 项目顶层包下创建启动类

@SpringBootApplication public class MarketingCenterApplication {

public static void main( String[] args ) {
    SpringApplication.run(MarketingCenterApplication.class, args);
}

}


启动项目的关键在于`SpringApplication.run()`

3. 顶层包下创建web/controller文件夹,新建一个IndexController

@Controller public class IndexController {

@RequestMapping("/")
@ResponseBody
public ResponseEntity index() throws Exception {
    return ResponseEntity.ok("index");
}

} ``` 运行MarketingCenterApplication,项目启动。访问localhost:8080,页面显示index

静态资源:

放在src/main/resources/static的资源文件可以直接访问到。 访问时不需要指定static这层路径。 假如有这样一个文件:src/main/resources/static/js/react.js,则访问路径为:http://localhost:8080/js/react.js

http://blog.csdn.net/isea533/article/details/50412212

Spring Boot 静态资源处理

results matching ""

    No results matching ""