环境搭建
导入相应的依赖
<!-- 继承SpringBoot官方指定的父工程 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
</parent>
<dependencies>
<!-- 加入Web开发所需要的场景启动器 -->
<dependency>
<!-- 指定groupId和artifactId即可,版本已在父工程中定义 -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!-- Maven构建过程相关配置 -->
<build>
<!-- 构建过程中所需要用到的插件 -->
<plugins>
<!-- 这个插件将SpringBoot应用打包成一个可执行的jar包 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
创建主启动类:
package com.atgui.spring.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
// 将当前类标记为一个SpringBoot应用
@SpringBootApplication
public class SpringBootMainType {
public static void main(String[] args) {
SpringApplication.run(SpringBootMainType.class,args);
}
}
创建Handler类
package com.atgui.spring.boot.handler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloHandler {
@RequestMapping("/get/spring/boot/hell/message")
public String getMessage(){
return "first blood!!!";
}
}
启动springboot的run dashboard
先配置
代码:
<option name="configurationTypes">
<set>
<option value="SpringBootApplicationConfigurationType" />
</set>
</option>
创建测试工程
加入依赖
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.atguigu.spring.boot</groupId>
<artifactId>pro02-spring-boot-read-yml</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- 继承SpringBoot官方指定的父工程 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
</parent>
<dependencies>
<!-- 加入Web开发所需要的场景启动器 -->
<dependency>
<!-- 指定groupId和artifactId即可,版本已在父工程中定义 -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<!-- 加入Web开发所需要的场景启动器 -->
<dependency>
<!-- 指定groupId和artifactId即可,版本已在父工程中定义 -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<!-- Maven构建过程相关配置 -->
<build>
<!-- 构建过程中所需要用到的插件 -->
<plugins>
<!-- 这个插件将SpringBoot应用打包成一个可执行的jar包 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
注解
基本原理
整合mybatis
注入依赖
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.atguigu.spring.boot</groupId>
<artifactId>pro03-spring-boot-mybatis</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
整合Redis
Thymeleaf