java - Springboot如何设置提升点击的值?
问题描述
这件事实际上让我发疯,因为我是使用 springboot 的新手。如何仅使用 void 方法来提高点击次数?谢谢你的任何建议:-)
public void raiseClick(int linkId) {
Optional<LinkEntity> ret;
try
{
ret = linkRepository.findById(linkId);
ret.get().setClickCount(+1); //i tried this but not success
}
catch (Exception e)
{
throw new DbException("Failed to raise by id link", e);
}
}
解决方案
public void raiseClick(final int linkId) {
LinkEntity ret;
try
{
ret = linkRepository.findById(linkId).orElseNull();
if(ret != null) {
ret.setClickCount(ret.getClickCount() + 1);
linkRepository.save(ret);
}
}
catch (Exception e)
{
throw new DbException("Failed to raise by id link", e);
}
}
推荐阅读
- opencv - 此类照片的最佳 OCR 实践
- c# - 修改循环内的元素会与 for 循环混淆
- angular - 如何将 BLK 主题添加到 Angular CLI 项目
- opencv - 使用自定义相机 (AruCo) 的 Unity3D 和 OpenCV
- c# - 在处理套接字耗尽和 DNS 回收时具有多个代理的 HttpClient
- ios - 准备 segue 函数无法将数据传递给另一个 VC Swift,
- c - 我可以仅使用指针代数在列表中来回移动并删除上一个/下一个指针吗?
- c# - 当我使用 localhost 连接时,如果我使用 IP 它不会连接
- java - 为什么 SonarLint 在方法名称上显示问题?
- vim - vim - 如何在映射上使用 complete_check()