Spring操作更新資料庫欄位
阿新 • • 發佈:2021-07-29
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_timesActivityReadMapper.java= read_times + 1 where customer_uid = #{customerUid} and activity_uid = #{activityUid} </update> </mapper>
public interface ActivityReadMapper extends BaseMapper<ActivityRead> { boolean increaseReadTime(@Param("customerUid") String customerUid, @Param("activityUid") String activityUid); }
此處是SpringBoot和mybatis-plus實現了此處一個介面的業務邏輯,把使用者報名人數用資料庫方式加一,而不使用get和set去存取實現