1.创建项目
方式一: 通过网站https://start.spring.io/
方式二: 通过开发工具(IDEA或者Eclipse自行百度)
2.修改pom.xml配置文件,添加必要的驱动包
1<?xml version="1.0" encoding="UTF-8"?> 2<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 <parent> 6 <groupId>org.springframework.boot</groupId> 7 <artifactId>spring-boot-starter-parent</artifactId> 8 <version>2.1.3.RELEASE</version> 9 <relativePath/> <!-- lookup parent from repository --> 10 </parent> 11 <groupId>com.xuanyin</groupId> 12 <artifactId>homektv</artifactId> 13 <version>0.0.1-SNAPSHOT</version> 14 <packaging>jar</packaging> 15 <!-- 统一管理jar包版本 --> 16 <properties> 17 <java.version>12</java.version> 18 <mybatis.spring.boot.version>2.0.0</mybatis.spring.boot.version> 19 <sqlite.jdbc.version>3.27.2.1</sqlite.jdbc.version> 20 </properties> 21 22 <dependencies> 23 <dependency> 24 <groupId>org.springframework.boot</groupId> 25 <artifactId>spring-boot-starter-web</artifactId> 26 </dependency> 27 <dependency> 28 <groupId>org.mybatis.spring.boot</groupId> 29 <artifactId>mybatis-spring-boot-starter</artifactId> 30 <version>${mybatis.spring.boot.version}</version> 31 </dependency> 32 <dependency> 33 <groupId>org.springframework.boot</groupId> 34 <artifactId>spring-boot-starter-test</artifactId> 35 <scope>test</scope> 36 </dependency> 37 <!-- druid 驱动 --> 38 <dependency> 39 <groupId>com.alibaba</groupId> 40 <artifactId>druid</artifactId> 41 <version>1.1.9</version> 42 </dependency> 43 <!-- sqlite3驱动包 --> 44 <dependency> 45 <groupId>org.xerial</groupId> 46 <artifactId>sqlite-jdbc</artifactId> 47 <version>${sqlite.jdbc.version}</version> 48 </dependency> 49 </dependencies> 50 51 <build> 52 <plugins> 53 <plugin> 54 <groupId>org.springframework.boot</groupId> 55 <artifactId>spring-boot-maven-plugin</artifactId> 56 <configuration> 57 <fork>true</fork> 58 </configuration> 59 </plugin> 60 <plugin> 61 <groupId>org.apache.maven.plugins</groupId> 62 <artifactId>maven-jar-plugin</artifactId> 63 <configuration> 64 <archive> 65 <manifest> 66 <addClasspath>true</addClasspath> 67 <classpathPrefix></classpathPrefix> 68 <mainClass>com.xuanyin.HomektvApplication</mainClass> 69 </manifest> 70 </archive> 71 </configuration> 72 </plugin> 73 </plugins> 74 </build> 75</project>
3.添加项目的数据库配置文件application.yml
1# Tomcat 2server: 3 tomcat: 4 uri-encoding: UTF-8 5 max-threads: 1000 6 min-spare-threads: 30 7 port: 8088 8#spring 9spring: 10 # 指定静态资源的路径 11 resources: 12 static-locations: classpath:/static/,classpath:/views/,file:${web.upload},file:${web.ueditorUpload} 13 datasource: 14 driver-class-name: org.sqlite.JDBC 15# 方式一: 引用外部文件 16# url: jdbc:sqlite:D:/eclipse/xy.db 17#方式二: 引用项目中的文件 18 url: jdbc:sqlite::resource:static/sqlite/xy.db 19 username: 20 password: 21 22# Mybatis配置 23mybatis: 24 mapperLocations: classpath:mapper/**/*.xml 25 #configLocation: classpath:mybatis.xml 26# sql打印 27logging: 28 level: debug 29 level.com.xuanyin: debug 30 path: logs/ 31# file: admin.log
4.添加测试Controller以及Server和Mapper等
注意各层级的注解的使用