spring提供的SQL工具类执行SQL脚本
发表于|更新于
|浏览量:
方向是比速度更重要的追求。——白岩松
这里主要是用到了org.springframework.jdbc.datasource.init.ScriptUtils#executeSqlScript(java.sql.Connection, org.springframework.core.io.Resource)方法
例如
1 | @BeforeAll |
这样的话就可以使用resources目录下的init.sql
相关推荐
2022-07-05
List<Map>聚合为单个Map<List>
科学是到处为家的,不过,在任何不播种的地方,是决不会得到丰收的。——赫尔岑 前两天有人给我的项目stream-query提交了PR,新增了一个Collector实现 我稍微研究了一下,发现与Collectors原生命名风格不统一,且不具备Collectors包下面的对象通用性,于是就移除了 但这个功能是可以保留的 我的实现如下: 1234567891011121314151617181920212223242526@Testvoid testReducing() { Set<Map<String, Integer>> nameScoreMapList = Stream.of( new HashMap<String, Integer>() {{ put("苏格拉底", 1); put("特拉叙马霍斯", 3); }}, Co...
2022-04-21
在SpringBoot单元测试中添加参数
我的肩上是风,风上是闪烁的星群。——北岛《结局或开始·献给遇罗克》 当时是解决一个issue而去查阅的 https://github.com/baomidou/mybatis-plus/issues/4417 最后代码如下: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566package com.ruben.mybatisplusissue;import javax.annotation.Resource;import org.junit.jupiter.api.Test;import org.junit.jupiter.api.extension.ExtendWith;import org.springframework.boot.SpringApplication;import org.springframework.boot.test.context.SpringBootCo...
2024-04-03
使用oceanbase
不息的劳作,是人生的胜利,也是艺术的法则。——巴尔扎克 介绍: OceanBase Database 是一个分布式关系型数据库。完全由蚂蚁集团自主研发。 OceanBase 基于 Paxos 协议以及分布式架构,实现了高可用和线性扩展。OceanBase 数据库运行在常见的服务器集群上,不依赖特殊的硬件架构。 https://github.com/oceanbase/oceanbase/blob/develop/README_CN.md 运行 1234567891011121314Github-Id-VampireAchao:wine achao$ # 部署一个mini模式实例Github-Id-VampireAchao:wine achao$ docker run -p 2881:2881 --name oceanbase-ce -e MODE=mini -d oceanbase/oceanbase-ceUnable to find image 'oceanbase/oceanbase-ce:latest' locallylatest: Pullin...
2024-05-15
jackson范型注意
放弃不难,但坚持一定很酷。——《解忧杂货店》 今天使用 Jackson 有个疑问,就是带范型的对象,Jackson 序列化后,范型会怎样处理: 就比如说{"data":{"data":1}},以及下面这个类: 1234@Datapublic static class Foo<T> { private T data;} 这个外层的 data 会反序列化出来什么类型呢? 实际上反序列化出来 LinkedHashMap 1234var obj = mapper.readValue(""" {"data":{"data":1}} """, Foo.class);Assertions.assertEquals(LinkedHashMap.class, obj.getData().getClass()); 如果我们需要继续解析成具体的类型,则...
2023-11-25
feign使用url参数传参@SpringQueryMap使用
与人沟通,最重要的事情是听取没有说出来的话。——德拉克 今天使用open-feign发起请求时发现个问题,我特别喜欢的url参数传参不好使了: 12345@FeignClient("another-service")public interface MyFeignClient { @GetMapping("/foo/bar") Foo<Bar> get(Foo bar);} 对应我们的controller 12345@GetMapping("foo/bar")public Foo<Bar> get(Foo bar) { // ... return foo;} 然后发起了请求发现根本没收到参数。。。 但如果我们添加了注解@RequestParam 12345@FeignClient("another-service")public interface MyFeignClient { @Get...
2021-06-12
parallelStream
我又愿中国青年只是向上走,不必理会这冷笑和暗箭。——鲁迅 我们在开发中经常使用stream去处理我们的集合 这里分享一个并行流:parallelStream 它可以允许我们的声明式编程以多线程并行的方式执行 首先我们可以比较一下性能 1234567891011121314List<Integer> list = new SecureRandom().ints().limit(10000000).boxed().collect(Collectors.toList());long startTime = System.nanoTime();// 求和操作int sum = list.stream().mapToInt(Integer::intValue).reduce(0, Integer::sum);System.out.println("普通stream求和结果:" + sum);long normalStreamEndTime = System.nanoTime();System.out.println("普通stream耗时:&q...
