1. 程式人生 > 其它 >Spring操作更新資料庫欄位

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去存取實現