SpringBoot学习(1)创建SpringBoot项目
1、创建一个工程,选择Spring Initialzr
此时有可能会出现spring-boot-maven-plugin这个依赖解决不了,然后加个version版本号即可成功引入:
自此,SpringBoot项目成功创建,创建好后的项目架构:
下面进行解析下默认生成的SpringBoot项目的目录介绍:
(1)直接给我们生成了一个主程序类Application
(2)resources文件目录结构:
(2.1)static:保存所有静态资源:js,css,images
(2.2)templates:保存所有模板页面
(2.3)application.properties:Springboot应用的配置文件,可以修改一些默认设置,如将tomcat端口修改成8081:
2、创建一个controller层,编写一个controller类:
package com.lrc.springboot_study.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @param
* @author lrc
* @create 2022/3/27
* @return
* @description
**/
@Controller
public class HelloController {
@ResponseBody
@RequestMapping("/hello")
public String hello(){
return "Hello World";
}
}
3、执行Appliction程序:
可以看到,SpringBoot项目已经启动完毕,接下来我们在浏览器发送请求:http://localhost:8080/hello
Hello World程序成功启动。