Spring操作更新数据库字段

ActivityInfoServiceImpl.java

@Service("IActivityInfoService")
@Slf4j
public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, ActivityInfo> implements IActivityInfoService {
    @Autowired
    private IActivityReadService activityReadService;
    @Autowired(required = false)
    private ActivityReadMapper activityReadMapper;

    private void addActivityReadRecord(String uid, ActivityInfo info, String shareCode) {
       activityReadService.getOne(Wrappers.<ActivityRead>lambdaQuery()
            .eq(ActivityRead::getActivityUid, activityUid)
            .eq(ActivityRead::getCustomerUid, useUid),false);    
            
            if(ObjectUtil.isNotNull(activityRead))
            activityReadMapper.increaseReadTime(uid , info.getUid());
    }
}

 

 

ActivityReadMapper.xml

<mapper namespace="com.xypopo.market.mapper.ActivityReadMapper">
    <update id="increaseReadTime">
        update activity_read set read_times = read_times + 1 where customer_uid = #{customerUid} and activity_uid = #{activityUid}
    </update>
</mapper>

 

 

ActivityReadMapper.java
public interface ActivityReadMapper extends BaseMapper<ActivityRead> {
    boolean increaseReadTime(@Param("customerUid") String customerUid, @Param("activityUid") String activityUid);
}

 

 

此处是SpringBoot和mybatis-plus实现了此处一个接口的业务逻辑,把用户报名人数用数据库方式加一,而不使用get和set去存取实现

 

Spring操作更新数据库字段

上一篇:《C++ Primer第五版》读书笔记(8)--GENERIC ALGORITHMS


下一篇:前后端分离的好处