springboot使用异步任务
一个简单的异步任务在springboot中已经为我们封装好,这里我们可以直接在函数上加@Async注解即可使用
注意,我们要接收返回值的话,函数返回类型需要为Future
例如,我们这里使用异步任务和建造者模式去创建一个对象
package com.ruben;import org.junit.jupiter.api.Test;import org.springframework.boot.test.context.SpringBootTest;import org.springframework.scheduling.annotation.Async;import org.springframework.scheduling.annotation.AsyncResult;import java.util.concurrent.ExecutionException;import java.util.concurrent.Future;/** * @ClassName: AsyncDemo * @Description: 我还没有写描述 * @Date: 2020/11/30 003 ...
@Transactional
事者,生于虑,成于务,失于傲。——管仲
如果想让该类或方法被事务支持,则可以加上@Transactional注解@Transactional有几个参数:value/transactionManager——是用来指定事务管理器,这个不太常用timeout——事务超时时间,为传播特性为PROPAGATION_REQUIRES_NEW和PROPAGATION_REQUIRED定制,创建新事务时旧事务的超时时间,出场率也不是特别高下面的则是常用的参数readOnly——是否为只读事务,如果为true时,进行查询操作效率会更高,但不能进行除查询外的操作,会报错rollbackFor/rollbackForClassName——指定需要回滚的异常noRollbackFor/noRollbackForClassName——指定不需要回滚的异常默认对编译异常不会滚
对非受检异常回滚,例如RuntimeException就会回滚事务
isolation——配置隔离级别事务丢失
回滚丢失——另一个事务回滚导致当前事务丢失
覆盖丢失——另一个事务提交导致当前事务丢失
org.springframewor ...
setInterval
坍圮的殿堂总还是庙,冷落的圣像依然是神。
在前端开发中我们或许想定时做一些操作
可以使用一个setInterval函数去做
// 定时控制台打印rubensetInterval(function () { console.log("ruben");}, 1000);// 定时控制台打印achao,注意这里是使用字符串形式写法setInterval('console.log("achao");', 1000);
可以打开控制台看到效果
springboot单元测试
每个圣人都有过去,每个罪人都有未来。 ――王尔德
我们在开发中经常会进行测试,如果是需要springboot环境,我们就可以使用spring-boot-starter-test
引入依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions>&l ...
vue路由NavigationDuplicated错误
有志者,事竟成,破釜沉舟,百二秦关终属楚;苦心人,天不负,卧薪尝胆,三千越甲可吞吴。——蒲松龄
如果遇到了Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location异常
可以在router里配置一下
import Vue from 'vue'import Router from 'vue-router'// 解决路由重复问题const originalPush = Router.prototype.pushRouter.prototype.push = function push(location) { return originalPush.call(this, location).catch(err => err)}Vue.use(Router)export default new Router({ mode: 'history', ...
实用避免空指针的工具类
一星陨落,黯淡不了星空灿烂;一花凋零,荒芜不了整个春天。——巴尔扎克
package com.ruben.utils;import com.ruben.pojo.User;import org.thymeleaf.expression.Lists;import sun.reflect.misc.ReflectUtil;import java.math.BigDecimal;import java.util.ArrayList;import java.util.List;import java.util.Optional;import java.util.concurrent.atomic.AtomicReference;/** * @ClassName: OptUtils * @Date: 2020/11/25 0025 15:02 * @Description: Optional工具类避免空指针 * @Author: <achao1441470436@gmail.com> */public class OptUtils { /** * @Met ...
elementUI隐藏组件
追求使你充实,成功和失败都是伴奏。——史铁生
关于ElementUI相信大家只要看过我这篇博客,都能有一定的了解
今天聊聊ElementUI官方文档都找不到的一个隐藏组件
那便是滚动条el-scrollbar
我们在开发中可能会用到数据量稍微多一点点的情况
例如我这里写的一个v-for
<div style="width: 20%"> <div v-for="(item, i) in tableData" :key="i"> <div v-text="item.name"></div> <div v-text="item.name"></div> <div v-text="item.name"></div> <div v-text="item.name"></div> <div v-tex ...
js打字机动画效果实现
坦白使人心地轻松的妙药。——西塞罗
实现打字机效果
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <style> * { margin: 0; padding: 0; } .d1 { width: 100%; height: 600px; background: #000; position: relative; } .zhezhao { position: absolute; top: 0; left: 0; ...
set取交集、并集、差集
蜡烛的美是绝唱的美,它以自焚的痛苦将自己化为光和热,照亮了别人。——鲁迅
HashSet<String> hashSet = new HashSet<>(Arrays.asList("0", "1", "2"));HashSet<String> hashSet2 = new HashSet<>(Arrays.asList("1", "2", "3"));// 取交集hashSet.retainAll(hashSet2);hashSet.forEach(System.out::println);System.out.println();HashSet<String> hashSet3 = new HashSet<>(Arrays.asList("0", "1", "2"));// 取并集hashSet3.addAll(hashSet2) ...
mybatis-plus基本使用
如果一个人不知道他要驶向哪个码头,那么任何风都不会是顺风。——小塞涅卡
上回我们写到封装了axios的工具类
今天我把OSS上传文件接了,可以去项目目录自取
前端项目:https://gitee.com/VampireAchao/my-vue-app.git
后端项目:https://gitee.com/VampireAchao/simple-springboot.git
传统代码以点到为止,所以这里就不再多聊OSS,想了解可以看这篇博客
然后我们聊聊mybatis-plus的基本使用
首先引入依赖,这个没什么好说的
<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.1.0</version></dependency>
然后我们按照之前创的表去对应新建一个DO
因为之前我们的表结构为这样【Tips:用的SQ ...