this thing actually driving me crazy, because i´am new at using springboot. How can I raise click count just only with void method? Thank you for any advice 🙂
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);
}
}
Advertisement
Answer
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);
}
}