llm-survey/backend/src/main/java/ltd/qubit/survey/service/BaseService.java
2025-02-20 15:34:19 +08:00

55 lines
957 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package ltd.qubit.survey.service;
import java.util.List;
import java.util.Optional;
import org.springframework.transaction.annotation.Transactional;
/**
* 基础Service接口定义通用的CRUD操作
*
* @param <T> 实体类型
* @param <K> 主键类型
*/
@Transactional(readOnly = true)
public interface BaseService<T, K> {
/**
* 新增
*
* @param entity 实体对象
* @return 实体对象
*/
@Transactional
T create(T entity);
/**
* 删除
*
* @param id 主键
*/
@Transactional
void delete(K id);
/**
* 更新
*
* @param entity 实体对象
* @return 实体对象
*/
@Transactional
T update(T entity);
/**
* 根据ID查询
*
* @param id 主键
* @return 实体对象
*/
Optional<T> findById(K id);
/**
* 查询所有
*
* @return 实体对象列表
*/
List<T> findAll();
}