scream每日站立会议4.22
1.昨天的成就:
完成演练计划分配模块的第一个功能,查看部门列表;

2.今天的任务:
集中冲刺时间:4个小时,晚上6:30到10:30
预计完成:演练计划分配模块之自动分配计划
3.遇到的问题:
(1)不清楚templates模板渲染html页面逻辑,总是在这里出一些不知道怎么回事的错误,最后决定先不使用templates模板,直接放入static中结合css和js开发
(2)单元测试repository出现问题
Spring Boot 在用嵌入式数据库替换 DataSource 失败了
解决方法:
调整 @AutoConfigureTestDatabase 注解,使数据库不嵌入数据库
成功!
4.开发代码示例:
contorller
public class DepartmentController {
private final DepartmentService departmentService;
@GetMapping("/unique")
public ResponseEntity<ApiResponse<List<String>>> getUniqueDepartments() {
try {
List<String> departments = departmentService.getUniqueDepartmentNames();
return ApiResponse.success(departments);
} catch (Exception e) {
log.error("获取部门列表失败: {}", e.getMessage(), e);
return ApiResponse.failure(HttpStatus.INTERNAL_SERVER_ERROR, "获取部门数据失败");
}
}
@GetMapping("/assign")
public ResponseEntity<ApiResponse<String>> departmentPage() {
return ApiResponse.success("assign"); // 对应前端页面路由
}
}
impl
@Service
public class DepartmentServiceImpl implements DepartmentService {
private final DepartmentRepository departmentRepository;
public DepartmentServiceImpl(DepartmentRepository departmentRepository) {
this.departmentRepository = departmentRepository;
}
@Override
public List<String> getUniqueDepartmentNames() {
return departmentRepository.findDistinctDepartmentNames();
}
}
repository
public interface DepartmentRepository extends JpaRepository<Department, Integer> {
@Query("SELECT distinct d.departmentName from Department d")
List<String> findDistinctDepartmentNames();
}

浙公网安备 33010602011771号