Spring Boot项目搭建
- 添加依赖
```
com.qianmi micro-service ${qm.micro.service.version}
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