SpringBoot整合Sqlite数据库流程

1.创建项目

  方式一: 通过网站https://start.spring.io/

  方式二: 通过开发工具(IDEA或者Eclipse自行百度)

2.修改pom.xml配置文件,添加必要的驱动包

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.xuanyin</groupId>
    <artifactId>homektv</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <!-- 统一管理jar包版本 -->
    <properties>
        <java.version>12</java.version>
        <mybatis.spring.boot.version>2.0.0</mybatis.spring.boot.version>
        <sqlite.jdbc.version>3.27.2.1</sqlite.jdbc.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>    
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>${mybatis.spring.boot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- druid 驱动 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.9</version>
        </dependency>
        <!-- sqlite3驱动包 -->
        <dependency>
            <groupId>org.xerial</groupId>
            <artifactId>sqlite-jdbc</artifactId>
            <version>${sqlite.jdbc.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix></classpathPrefix>
                            <mainClass>com.xuanyin.HomektvApplication</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

3.添加项目的数据库配置文件application.yml

# Tomcat
server:
    tomcat:
        uri-encoding: UTF-8
        max-threads: 1000
        min-spare-threads: 30
    port: 8088
#spring
spring:
    # 指定静态资源的路径
    resources:
        static-locations: classpath:/static/,classpath:/views/,file:${web.upload},file:${web.ueditorUpload}
    datasource:
        driver-class-name: org.sqlite.JDBC
# 方式一:  引用外部文件
#        url: jdbc:sqlite:D:/eclipse/xy.db
#方式二: 引用项目中的文件
        url: jdbc:sqlite::resource:static/sqlite/xy.db
        username: 
        password: 
               
# Mybatis配置
mybatis:
    mapperLocations: classpath:mapper/**/*.xml
    #configLocation: classpath:mybatis.xml
# sql打印
logging:
    level: debug
    level.com.xuanyin: debug
    path: logs/
#    file: admin.log

 

4.添加测试Controller以及Server和Mapper等

  注意各层级的注解的使用

    原文作者:sqlite
    原文地址: https://www.cnblogs.com/zblwyj/p/10668803.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞