spring Boot 整合H2+Mybatis环境搭建

需求:

我的毕设里做了一个仿微信的聊天功能,我想做了个web的仿微信聊天Demo,

 

 

 

解决办法:

参考开源的项目,

技术栈:springboot+vue+H2+Mybatis(通用Mapper)

H2安装:

官网:http://www.h2database.com/html/main.html

不知道学啥的时候遇到了这个数据库,轻量。嵌入式。使用和Mysql类似的。

  • 非常快速的开源JDBC API
  • 嵌入式和服务器模式;内存数据库
  • 基于浏览器的控制台应用程序
  • 占用空间小:大约2 MB的jar文件大小

安装很简单:

1、导入依赖包 : H2+springboot整合Mybatis+通用Mapper

复制代码
  <!--mybitis整合H2-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.1.1</version>
        </dependency>
        <!--H2数据库-->
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <!--tkmybatis -->
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-spring-boot-starter</artifactId>
            <version>1.1.4</version>
        </dependency>
复制代码

 

2、配置文件编写:(这里需要写两个文件来加载数据库信息)

复制代码
server.port=8081

spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:test 
spring.datasource.schema=classpath:db/schema.sql
spring.datasource.data=classpath:db/data.sql
spring.datasource.username=sa
spring.datasource.password=sa
#http://本地端口/h2-console 通过项目来进行访问数据库
spring.h2.console.enabled=true
复制代码

 

 

 

3、浏览器访问:

 

 

 

 

 

posted @   山河已无恙  阅读(2514)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示