mybatis缓存解析

mybatis的缓存 首先来看下mybatis对缓存的规范,规范嘛就是定义的接口啦。 缓存接口 ​ Cache接口 定义了缓存的方法 public interface Cache { /**获取缓存的id * @return The identifier of this cache */ String getId(); /**添加缓存 * @param key Can be any object but usually it is a {@link CacheKey} * @param value The result of a select. */ void putObject(Object key, Object value); /**根据缓存键获取缓存 * @param key The key * @return The object stored in the cache. */ Object getObject(Object key); /**移除缓存 * As of 3.3.0 this method is only called during a rollback * for any previous value that was missing in the cache. * This lets any blocking cache to release the lock that * may have previously put on the key. * A blocking cache puts a lock when a value is null * and releases it when the value is back again. * This way other threads will wait for the value to be * available instead of hitting the database. * * * @param key The key * @return Not used */ Object removeObject(Object key); /** * Clears this cache instance */ void clear(); /** * Optional. This method is not called by the core. * * @return The number of elements stored in the cache (not its capacity). */ int getSize(); /** * Optional. As of 3.2.6 this method is no longer called by the core. * * Any locking needed by the cache must be provided internally by the cache provider. * * @return A ReadWriteLock */ ReadWriteLock getReadWriteLock(); } 实现 ...

November 17, 2021 · 12 min

mybatis的mapper执行过程

November 10, 2021 · 0 min

mybatis核心组件

sequenceDiagram participant SqlSession participant Excutor participant StatementHandler participant parameterHandler participant ResultSetHandler participant TypeHandler participant ResultSet participant JDBC SqlSession->>Excutor: Excutor->>StatementHandler: StatementHandler-->>parameterHandler: StatementHandler-->>JDBC: parameterHandler-->>TypeHandler: parameterHandler->>JDBC: JDBC->>ResultSet: ResultSet-->>TypeHandler: ResultSet-->>ResultSetHandler: TypeHandler-->>ResultSetHandler: ResultSetHandler->>StatementHandler: StatementHandler->>Excutor: Excutor->>SqlSession: Note left of SqlSession: asa flowchart TD subgraph configuration mappedStatement1 --> mappedStatement2 end configuration: ...

November 10, 2021 · 2 min

05_GC and Tuning

GC和GC Tuning GC的基础知识 1.什么是垃圾 C语言申请内存:malloc free C++: new delete c/C++ 手动回收内存 Java: new ? 自动内存回收,编程上简单,系统不容易出错,手动释放内存,容易出两种类型的问题: ...

October 8, 2021 · 17 min

easyExcel自定义合并单元格

easyExcel本身支持简单的单元格合并,一共有两种合并策略: 一次性的合并策略(OnceAbsoluteMergeStrategy) 循环的合并策略(LoopMergeStrategy) /** * 合并单元格 * <p> * 1. 创建excel对应的实体对象 参照{@link DemoData} {@link DemoMergeData} * <p> * 2. 创建一个merge策略 并注册 * <p> * 3. 直接写即可 * * @since 2.2.0-beta1 */ @Test public void mergeWrite() { // 方法1 注解 String fileName = TestFileUtil.getPath() + "mergeWrite" + System.currentTimeMillis() + ".xlsx"; // 在DemoStyleData里面加上ContentLoopMerge注解 // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭 EasyExcel.write(fileName, DemoMergeData.class).sheet("模板").doWrite(data()); // 方法2 自定义合并单元格策略 fileName = TestFileUtil.getPath() + "mergeWrite" + System.currentTimeMillis() + ".xlsx"; // 每隔2行会合并 把eachColumn 设置成 3 也就是我们数据的长度,所以就第一列会合并。当然其他合并策略也可以自己写 LoopMergeStrategy loopMergeStrategy = new LoopMergeStrategy(2, 0); // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭 EasyExcel.write(fileName, DemoData.class).registerWriteHandler(loopMergeStrategy).sheet("模板").doWrite(data()); } 但是往往实际应用中,我们并不能立马指定合并的单元格,就比如我这次需要根据订单id相同的合并单元格,但是数据还没查询出来时,我是不知道哪些要合并的,而我只知道两个要求: ...

October 8, 2021 · 5 min
总访问量 总访客数