当前位置: 首页 > news >正文

h2数据库模拟mysql进行单元测试遇到的问题

使用h2数据库进行springboot的单元测试的时候出现的几个问题

1.h2数据库插入json数据的时候,默认是json String的形式(josn数据入库的时候有转义字符),导致查询出来的json数据在进行处理的时候无法解析成jsonNode

操作:

在单元测试插入数据的时候,在json对应的字段最后加上FORMAT JSON

即 insert into tabelA(json字段,string字段) values(“{‘A":“B”}’ FORMAT JSON, ”string数据段“)即可正确插入json数据(入库的时候无转义符)

2.h2数据库不支持mysql的批量更新操作,也不支持mysql的replace into语句。

--批量更新(H2不支持)<update id="increaseBatch"  parameterType="java.util.List"><foreach collection="list" item="item" index="index" open="" close="" separator=";">update product<set>quantity = quantity + #{item.updateQuantity}, modify_time = #{item.modifyTime}</set>where id = #{item.productId}</foreach></update>--批量插入(H2支持)
<insert id="insertItems" keyProperty="id" parameterType="java.util.List" useGeneratedKeys="true"><selectKey keyProperty="id" order="AFTER" resultType="long">SELECT LAST_INSERT_ID()</selectKey>INSERT INTO bill_item(bill_id,product_id,product_name,product_quantity,product_quantity_after,product_price,product_amount)VALUES<foreach close="" collection="list" index="index" item="item" open="" separator=",">(#{item.billId},#{item.productId},#{item.productName},#{item.productQuantity},#{item.productQuantityAfter},#{item.productPrice},#{item.productAmount})</foreach></insert>

3.mysql中的json_contain等sql函数,在h2数据库中也是没有的,需要自己定义。


http://www.mrgr.cn/news/51164.html

相关文章:

  • 基于SSM党建工作小秘书管理系统的设计
  • RAG书籍《大模型RAG实战》出版
  • 每日新闻掌握【2024年10月15日 星期二】
  • 低代码策略量化平台更新|大模型agents生态的一些思考
  • 视频格式在线转换,五种超实用的视频格式转换工具!
  • 【scene_manager_msgs】ROS2 自定义消息、服务的包
  • 用AI搞流量 | AI做好运壁纸号, 3个月涨粉6.4W
  • 通过SSH登录Linux系统并设置免密码登录
  • nvm安装,node多版本管理
  • MySQL创建和管理表
  • react18中实现简易增删改查useReducer搭配useContext的高级用法
  • 使用豆包MarsCode 来处理 Excel 的数据吧!
  • 4种鼓励创业创新的方法
  • GEE 批量删除 Assets 资产文件夹
  • 能源水务储能的可视化需求真多,我都忙不过来了。
  • 蓝紫激光模组常见的基本特性
  • 和数集团东南亚市场工作会议圆满举行
  • 给el-dialog的整体加动态class
  • NumPy 数组操作:从入门到精通
  • 2024年Flutter从入门到精通全网最全学习路线指南