org.zodiac.mybatisplus.base.BaseEnhancedServiceImpl Maven / Gradle / Ivy
package org.zodiac.mybatisplus.base;
import org.springframework.validation.annotation.Validated;
import org.zodiac.mybatisplus.util.MyBatisPlusUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
@Validated
public abstract class BaseEnhancedServiceImpl, T> extends ServiceImpl implements BaseEnhancedService {
@Override
public T getOne() {
/*避免泛型继承出现问题 https://blog.csdn.net/qq_38688267/article/details/112621293 */
return getOne(entityLambdaQuery());
}
@Override
public T getOne(boolean throwEx) {
Wrapper queryWrapper = entityLambdaQuery();
if (throwEx) {
return baseMapper.selectOne(queryWrapper);
}
return SqlHelper.getObject(log, baseMapper.selectList(queryWrapper));
}
@Override
public LambdaQueryWrapper entityLambdaQuery() {
return MyBatisPlusUtil.lambdaQuery(entityClass);
}
@Override
public LambdaUpdateWrapper entityLambdaUpdate() {
return MyBatisPlusUtil.lambdaUpdate(entityClass);
}
}