t_pt_room → PtRoomBo,如 PtRoomBoVo,如 PtRoomVoRemote + 实体名 + Dto,如 RemoteRoomDtoI + 实体名 + Service,如 IPtRoomServiceServiceImpl,如 PtRoomServiceImplMapper,如 PtRoomMapperController,如 PtRoomControllerRemote + 功能 + Service,如 RemotePtRoomService| 操作 | 前缀 | 示例 |
|---|---|---|
| 查询单个 | queryById / getById | queryById(Long id) |
| 查询列表 | queryList / selectList | queryList(Bo bo) |
| 分页查询 | queryPageList / selectPage | queryPageList(Bo bo, PageQuery query) |
| 新增 | insertByBo / save | insertByBo(Bo bo) |
| 修改 | updateByBo / update | updateByBo(Bo bo) |
| 删除 | deleteByIds / remove | deleteByIds(Collection<Long> ids) |
| 校验 | validateXxx | validateUnique(Bo bo) |
is 开头(避免与 getter 冲突)常量使用全大写下划线分隔
// 推荐
private String userName;
private Boolean enabled;
private static final String DEFAULT_STATUS = "0";
// 避免
private String user_name;
private Boolean isEnabled;
@Slf4j // 日志
@RequiredArgsConstructor // 构造器注入
@Service // Spring Bean
@DubboService // Dubbo服务(如需要)
public class XxxServiceImpl implements IXxxService {
}
@Validated // 参数校验
@RequiredArgsConstructor // 构造器注入
@RestController // REST控制器
@RequestMapping("/room") // 请求路径
public class PtRoomController extends BaseController {
}
@NotBlank(message = "名称不能为空", groups = {AddGroup.class, EditGroup.class})
@ExcelProperty(value = "名称")
private String name;
@Service
@RequiredArgsConstructor
public class PtRoomServiceImpl implements IPtRoomService {
private final PtRoomMapper baseMapper;
private final IPtAreaService areaService;
}
// 不推荐
@Autowired
private PtRoomMapper baseMapper;
/**
* 房间定义对象 t_pt_room
*
* @author bing
* @date 2024-08-09
*/
/**
* 查询房间列表
*
* @param bo 查询条件
* @return 房间列表
*/
List<PtRoomVo> queryList(PtRoomBo bo);
// 1. 构建查询条件
PtUserAccountBo bo = new PtUserAccountBo();
bo.setCategory(TRAINEE_CATEGORY);
// 2. 设置分页参数
PageQuery pageQuery = new PageQuery();
pageQuery.setPageNum(Math.max(queryDto.getPageNum(), 1));
// 3. 执行查询并转换结果
TableDataInfo<PtUserAccountVo> result = userAccountService.queryPageList(bo, pageQuery);
public R<RemoteTeacherDto> selectTeacherById(Long userId) {
PtUserAccountVo vo = userAccountService.queryById(userId);
if (vo == null || !TEACHER_CATEGORY.equals(vo.getCategory())) {
return R.fail("未找到对应的教师信息");
}
return R.ok(convertToTeacherDto(vo));
}
if (room == null) {
throw new ServiceException("房间不存在");
}
PageQuery pageQuery = new PageQuery();
pageQuery.setPageNum(queryDto.getPageNum() != null ? Math.max(queryDto.getPageNum(), 1) : 1);
pageQuery.setPageSize(queryDto.getPageSize() != null ? Math.min(Math.max(queryDto.getPageSize(), 1), 500) : 10);
TableDataInfo<RemoteXxxDto> pageData = TableDataInfo.build();
pageData.setRows(dtoList);
pageData.setTotal(result.getTotal());
return pageData;
import cn.hutool.core.collection.CollectionUtil;
if (CollectionUtil.isEmpty(list)) {
return Collections.emptyList();
}
if (vo == null) {
return null;
}
public class XxxConstants {
/** 教师类型编码 */
public static final String TEACHER_CATEGORY = "1";
/** 学员类型编码 */
public static final String TRAINEE_CATEGORY = "2";
}
@Getter
@AllArgsConstructor
public enum StatusEnum {
NORMAL("0", "正常"),
DISABLED("1", "停用");
private final String code;
private final String desc;
}
@Slf4j
@Service
public class XxxServiceImpl {
public void doSomething() {
log.info("处理开始,参数:{}", param);
log.debug("调试信息:{}", detail);
log.error("处理失败", e);
}
}