1、使用Spring Initialize向导创建项目
![](https://img.haomeiwen.com/i2765653/a91ba6bc2b7808a3.png)
![](https://img.haomeiwen.com/i2765653/1d288ea8d3ff6602.png)
![](https://img.haomeiwen.com/i2765653/59854ed87cbaa9b1.png)
![](https://img.haomeiwen.com/i2765653/bf4b67ca8d233500.png)
![](https://img.haomeiwen.com/i2765653/23f279bded2ab434.png)
2、创建成功后springboot相关的在pom.xml中配置已经注入成功了
3、创建HelloController.java文件
![](https://img.haomeiwen.com/i2765653/edec3d0dcb2e9809.png)
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
// 这个类的所有方法返回的数据直接写给浏览器,如果是对象转为json数据
//@Controller
//@ResponseBody
@RestController // 相当于 @Controller @ResponseBody
public class HelloController {
@RequestMapping("/hello")
public String hello(){
return "Hello World!";
}
}
4、resources下的目录文件
![](https://img.haomeiwen.com/i2765653/b1a7e7ed2f06201e.png)
- static:保存所有的静态资源:js、css、images
- templates:保存所有的模板页面;(SpringBoot默认jar包使用嵌入式的Tomcat,默认不支持JSP页面);可以使用模板引擎(freemarker、thymeleaf)
- application.properties:SpringBoot应用的配置文件;可以修改一些默认设置,比如修改端口号将默认的端口号8080修改为8081
![](https://img.haomeiwen.com/i2765653/cc7b7950394d4baf.png)
网友评论