Initial project

This commit is contained in:
Timi
2025-07-08 14:34:32 +08:00
parent 271e2ae673
commit c27146aa91
56 changed files with 3050 additions and 80 deletions

View File

@ -0,0 +1,104 @@
package com.imyeyu.spring.mapper;
import com.imyeyu.spring.util.SQLProvider;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import java.util.List;
/**
* 基本 SQL 映射,子接口可以不实现
*
* @author 夜雨
* @version 2021-07-16 09:40
*/
public interface BaseMapper<T, P> {
/**
* 排序方式
*
* @author 夜雨
* @version 2023-09-05 22:14
*/
enum OrderType {
ASC,
DESC
}
static final String NOT_DELETE = " AND `deleted_at` IS NULL ";
static final String LIMIT_1 = " LIMIT 1";
static final String UNIX_TIME = " FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000) ";
static final String PAGE = NOT_DELETE + " LIMIT #{offset}, #{limit}";
/**
* 统计数据量
*
* @return 数据量
*/
long count();
/**
* 获取部分数据
*
* @param offset 偏移
* @param limit 数据量
* @return 数据列表
*/
List<T> list(long offset, int limit);
/**
* 创建数据。默认自增主键为 id如需修改请重写此接口
*
* @param t 数据对象
*/
@InsertProvider(type = SQLProvider.class, method = "insert")
@Options(useGeneratedKeys = true, keyProperty = "id")
void insert(T t);
/**
* 根据 ID 获取对象
*
* @param id 索引
* @return 数据对象
*/
@SelectProvider(type = SQLProvider.class, method = "select")
T select(P id);
@SelectProvider(type = SQLProvider.class, method = "selectByExample")
T selectByExample(T t);
@SelectProvider(type = SQLProvider.class, method = "selectAllByExample")
List<T> selectAllByExample(T t);
/**
* 修改数据
*
* @param t 数据对象
*/
@UpdateProvider(type = SQLProvider.class, method = "update")
void update(T t);
/**
* 软删除
*
* @param id 索引
*/
@UpdateProvider(type = SQLProvider.class, method = "delete")
void delete(P id);
/**
* 销毁(物理删除)
*
* @param id 索引
*/
@DeleteProvider(type = SQLProvider.class, method = "destroy")
void destroy(P id);
}