初始化springboot项目
添加web依赖,基于springboot2.1.3稳定版本
初始化spring boot项目地址 https://start.spring.io/
包名:com.nqmysb.scaffold
导入IDE
下载项目,我这里使用eclipse ,导入eclipse之后如下图
编写控制器
写一个控制器,并启动查看结果,这里直接将controller写在入口类
@RestController
@SpringBootApplication
public class SpringbootScaffoldApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootScaffoldApplication.class, args);
}
@RequestMapping("/index")
public String index(String[] args) {
System.out.println("hello world");
return "springboot2.0 hello!";
}
}
验证访问
通过访问浏览器查看结果 http://localhost:8080/index ,浏览器显示和控制台打印正常!
热加载配置
在项目pom.xml文件中加入热加载依赖,重新启动,修改代码时项目会自动重启更新项目。
<!-- hot reload -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
自定义启动banner图案
在src/main/recesources下新建一个banner.txt文件,内容如下:佛系程序员
${AnsiColor.BRIGHT_YELLOW}
===================================================================================
_____ _ _ _ _ _ _ _
| __ \| | | | | | | | | | | | | |
| |__) | |__ ___ | |_ ___ | |__| | __ _ ___| | ____ _| |_| |__ ___ _ __
| ___/| '_ \ / _ \| __/ _ \ | __ |/ _` |/ __| |/ / _` | __| '_ \ / _ \| '_ \
| | | | | | (_) | || (_) | | | | | (_| | (__| < (_| | |_| | | | (_) | | | |
|_| |_| |_|\___/ \__\___/ |_| |_|\__,_|\___|_|\_\__,_|\__|_| |_|\___/|_| |_|
// _ooOoo_ //
// o8888888o //
// 88" . "88 //
// (| ^_^ |) //
//