以下是基于表名dste_project_indicator
(項目指標表)的完整命名示例,覆蓋各類增刪改查場景:
1. 表名與實體類映射
// 表名:dste_project_indicator
// 實體類:DsteProjectIndicatorEntity
public class DsteProjectIndicatorEntity {private Long id;private Long projectId;private String indicatorCode;private String indicatorName;// 其他字段...
}
2. 基礎增刪改查方法
// 新增
int insert(DsteProjectIndicatorEntity entity);
int save(DsteProjectIndicatorEntity entity);// 修改
int update(DsteProjectIndicatorEntity entity);
int modify(DsteProjectIndicatorEntity entity);// 邏輯刪除
int logicDeleteById(Long id);
int markAsDeletedById(Long id);// 物理刪除
int deleteById(Long id);
int removeById(Long id);// 查詢單條
DsteProjectIndicatorEntity selectById(Long id);
DsteProjectIndicatorEntity getById(Long id);// 查詢多條
List<DsteProjectIndicatorEntity> selectList(QueryParam param);
List<DsteProjectIndicatorEntity> listByCondition(QueryParam param);
3. 批量操作方法
// 批量新增
int batchInsert(List<DsteProjectIndicatorEntity> entityList);
int insertBatch(List<DsteProjectIndicatorEntity> entityList);// 批量修改
int batchUpdate(List<DsteProjectIndicatorEntity> entityList);
int updateBatch(List<DsteProjectIndicatorEntity> entityList);// 批量邏輯刪除
int batchLogicDeleteByIds(List<Long> ids);
int batchMarkAsDeleted(List<Long> ids);// 批量物理刪除
int batchDeleteByIds(List<Long> ids);
int batchRemoveByIds(List<Long> ids);
4. 條件操作方法
// 條件新增(根據另一個實體創建)
int insertByEntity(DsteProjectIndicatorEntity template);
int saveFromTemplate(DsteProjectIndicatorEntity template);// 條件修改(根據條件更新部分字段)
int updateByCondition(UpdateParam updateParam, QueryParam queryParam);
int modifyFieldsByCondition(Map<String, Object> fields, QueryParam condition);// 條件邏輯刪除
int logicDeleteByCondition(QueryParam param);
int disableByCondition(QueryParam param);// 條件物理刪除
int deleteByCondition(QueryParam param);
int removeByCondition(QueryParam param);
5. 分頁與統計方法
// 分頁查詢
Page<DsteProjectIndicatorEntity> selectPage(PageParam pageParam, QueryParam queryParam);
IPage<DsteProjectIndicatorEntity> pageByCondition(PageParam page, QueryParam condition);// 統計查詢
Long countByCondition(QueryParam param);
Integer countActiveIndicators();
6. 復雜業務方法
// 按項目ID查詢指標列表
List<DsteProjectIndicatorEntity> selectByProjectId(Long projectId);
List<DsteProjectIndicatorEntity> listIndicatorsByProject(Long projectId);// 按指標編碼查詢(唯一鍵)
DsteProjectIndicatorEntity selectByCode(String indicatorCode);
DsteProjectIndicatorEntity getByUniqueCode(String code);// 邏輯刪除并關聯刪除子指標
int logicDeleteWithChildren(Long id);
int disableIndicatorCascade(Long id);// 批量新增并返回主鍵
List<Long> batchInsertAndReturnIds(List<DsteProjectIndicatorEntity> entityList);
命名原則總結
-
動詞選擇:
- 新增:
insert
/save
/create
- 修改:
update
/modify
/edit
- 刪除:
delete
/remove
(物理)、logicDelete
/disable
/markAsDeleted
(邏輯) - 查詢:
select
/get
/list
/page
- 新增:
-
參數與返回值:
- 單數形式(如
insert
)處理單個實體 - 復數形式(如
batchInsert
)處理集合 - 帶
ByXXX
后綴表示按條件操作
- 單數形式(如
-
業務場景:
- 包含業務對象名稱(如
ProjectIndicator
) - 特殊場景使用特定動詞(如
archive
/invalidate
/restore
)
- 包含業務對象名稱(如
-
代碼風格一致性:
- 保持項目內方法命名統一(如統一用
insert
或save
) - 使用
Entity
/Param
/VO
明確參數類型
- 保持項目內方法命名統一(如統一用
示例實現(MyBatis Mapper)
public interface DsteProjectIndicatorMapper {// 單條新增@Insert("INSERT INTO dste_project_indicator (...) VALUES (...)")int insert(DsteProjectIndicatorEntity entity);// 批量新增@Insert("<script>INSERT INTO dste_project_indicator (...) VALUES " +"<foreach collection='list' item='item' separator=','>(...)</foreach></script>")int batchInsert(@Param("list") List<DsteProjectIndicatorEntity> entityList);// 條件邏輯刪除@Update("UPDATE dste_project_indicator SET delete_at = NOW() WHERE project_id = #{projectId}")int logicDeleteByProjectId(@Param("projectId") Long projectId);// 分頁查詢List<DsteProjectIndicatorEntity> selectPage(@Param("page") PageParam pageParam, @Param("condition") QueryParam condition);
}
根據實際業務需求(如數據庫類型、ORM框架、事務要求等),選擇最合適的命名方式和實現策略。