1、《Spring Boot 入门》中是使用创建Maven项目,然后导入Spring Boot依赖的方式,虽然相比传统做法已经很快了,但是IDEA等主流Java编辑器都支持快速构建Spring项目
截图如下
生成的项目目录结构
默认项目结构
src/main/java下是源码,主程序 "SpringBoot01HelloworldQuickApplication" 已经生成好了,只需要写我们自己的逻辑业务代码,注意Spring 组件默认必须在主程序同包或者其子包下面
controller在主程序SpringBoot01HelloworldQuickApplication所在包(com.atguigu.springbot)下面
src/main/resources 下是应用资源
static:保存所有的静态资源,如 以前的 js、css、images、音视频文件等;
templates:保存所有的模板页面,注意 Spring Boot 默认 jar 包使用嵌入式的 Tomcat,默认不支持JSP页面);但可以使用模板引擎,如 freemarker、thymeleaf;
application.properties:Spring Boot 应用的配置文件,用来修改Spring Boot 的默认设置,如Tomcat的默认端口号等;
src/test:Maven的测试目录
package com.atguigu.springboot.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
//这个类的所有方法返回的数据直接写给浏览器,(如果是对象转为json数据)
/*@ResponseBody
@Controller*/
@RestController //这个注解相当于上面两个注解
public class HelloController {
@RequestMapping("/hello")
public String hello(){
return "hello world quick!";
}
// RESTAPI的方式
}