| | |
| | | package com.lunhan.xxx.repository; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.lunhan.xxx.common.PagerResult; |
| | | import com.lunhan.xxx.common.enums.ELogger; |
| | |
| | | import org.slf4j.Logger; |
| | | import org.springframework.dao.EmptyResultDataAccessException; |
| | | |
| | | import javax.persistence.Table; |
| | | import java.io.Serializable; |
| | | import java.lang.reflect.ParameterizedType; |
| | | import java.util.Collection; |
| | |
| | | * |
| | | * @param <T> 数据实体 |
| | | */ |
| | | public abstract class BasicMapperImpl<T> implements BasicMapper<T> { |
| | | protected BaseMapper<T> DB; |
| | | public abstract class BasicMapperImpl<T, M extends BasicMapper<T>> implements BasicMapper<T> { |
| | | protected M DB; |
| | | protected Class<T> clazz; |
| | | protected String tableName; |
| | | |
| | |
| | | /** |
| | | * 构造方法 |
| | | */ |
| | | public BasicMapperImpl(BaseMapper<T> db) { |
| | | public BasicMapperImpl(M db) { |
| | | this.clazz = (Class<T>) ( |
| | | (ParameterizedType) getClass().getGenericSuperclass() |
| | | ).getActualTypeArguments()[0]; |
| | | this.DB = db; |
| | | Table annotation = clazz.getAnnotation(Table.class); |
| | | TableName annotation = clazz.getAnnotation(TableName.class); |
| | | if (null == annotation) { |
| | | this.tableName = StringUtils.camelToUnderline(clazz.getSimpleName().replace("PO", "")); |
| | | return; |
| | | } |
| | | this.tableName = annotation.name(); |
| | | this.tableName = annotation.value(); |
| | | } |
| | | |
| | | public LambdaQueryWrapper<T> query() { |