执行该方法时就会启动新的线程处理
@Override
//异步操作,Spring提供的新建线程的注解,这要执行这个方法SpringBoot就会启动一个新的线程来处理,也要在SpringBoot启动类上增加注解@EnableAsync
@Async
public void saveHistory(Long userId, Long id) {
//只有用户首次浏览才保存
LambdaQueryWrapper<BrowsingHistory> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(BrowsingHistory::getUserId,userId);
queryWrapper.eq(BrowsingHistory::getRoomId,id);
BrowsingHistory browsingHistory = browsingHistoryMapper.selectOne(queryWrapper);
//浏览过,直接更新浏览时间插入数据库
if(browsingHistory!=null){
browsingHistory.setBrowseTime(new Date());
browsingHistoryMapper.updateById(browsingHistory);
}else {
//没浏览过插入新的浏览数据,房间id,用户id和浏览时间
BrowsingHistory history = new BrowsingHistory();
history.setRoomId(id);
history.setUserId(LoginUserHolder.getLoginUser().getUserId());
history.setBrowseTime(new Date());
browsingHistoryMapper.insert(history);
}
}
@SpringBootApplication
@EnableAsync
public class AppWebApplication {
public static void main(String[] args) {
SpringApplication.run(AppWebApplication.class,args);
}
}
推荐阅读:
linux yum install报错已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
尚硅谷尚庭公寓
Mybatis-Plus更新策略修改
在SpringMVC中接收枚举类型参数
阿里云短信验证码服务
《尚庭公寓》162集确认租约按钮没反应
SpringBoot定时任务
minIO在windows下设置用户名和密码、固定端口
RedistTemplate类型选择和使用
jkson时间格式设置
行动消除疑虑