今天准备创建一个SpringBoot项目,结果发现网络不好.于是就上网搜索到相关的文章学习.
帮助链接:Idea之没有网络的情况下创建SpringBoot项目
1. 创建maven项目
2. 添加依赖
<!--springboot基础的创建 告诉maven我们要创建的是一个springboot项目-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<mybatis-plus>3.4.2</mybatis-plus>
<knife4j>2.0.9</knife4j>
<mysql>8.0.13</mysql>
</properties>
<dependencies>
<!--SpringBook所需的jar包 默认不需要写版本号 继承父类的版本号-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--Mysql依赖-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql}</version>
</dependency>
<!-- lombok依赖 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus}</version>
</dependency>
<!--Java MVC框架集成Swagger生成Api文档-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>${knife4j}</version>
</dependency>
</dependencies>
<!--spirng 打包成war包-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
3. 编写启动类
@SpringBootApplication //启动类
@MapperScan(basePackages = "com.hanyulin.demo.mapper") // 扫描mapper
public class TestApplication {
public static void main(String[]args)
{
SpringApplication.run(TestApplication.class,args);
}
}
4. application.yml连接数据库
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: 123456
url: jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
server:
port: 9090
5. 编写controller
@RestController
public class TestController {
@RequestMapping
public String HelloWord()
{
return "HelloWorld";
}
}
6. 运行项目
7. 目录结构
写博客是博主记录自己的学习过程,如果有错误,请指正,谢谢!