一 springboot 是什么?
1.应用SSM开发时候是不是须要导入很多依赖?
2.在引入SSM的依赖是纠结版本是否兼容?
3.配置文件扩散在多个中央批改起繁琐?
4.每次新建我的项目的时候根底配置要重复编写?来试试springboot!这个框架就是文理解决下面这些问题而生的!当然它还有更多长处,咱们一起来看看!
二 先从一个hello world 我的项目开始
1. 关上idea新建一个maven project 抉择web app骨架
2. 欠缺目录构造增加 java resource等文件夹,补全三层架构的文件夹(controller service dao/Mapper)
3. 在pom.xml中增加如下内容
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.3.3.RELEASE</version>
</parent>
#如果要指定jdk版本
<properties>
<java.version>1.8</java.version?
</properties>
#上面这个依赖是springboot的官网启动器依赖当前很多相似的启动器都是这个样子,因为咱们在下面指定了父工程,springboot会主动帮咱们治理版本,无需编写这些依赖的版本号
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
4.回到java文件夹中编写启动类
在Java文件夹内编写Applicatiton启动类
```
package com.yang;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/*
- 工程入口类
- */
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class,args);
}
}
5. 在controller中编写一个HelloController
package com.yang.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HelloController {
@ResponseBody
@RequestMapping("/hello")
public String Hello (){
return "<h1>Hello I Am Yang </h1>";
}
}
6. 在Application类中运行就能够了
在浏览器中输出 localhost:8080/hello
就能够见证奇观了
发表回复