首页 > 解决方案 > 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);
    }
}

标签: java

解决方案


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);
    }
}

推荐阅读