跳到主要内容

后端代码结构

SurveyKing Pro 后端采用 Spring Boot 3.x + MyBatis Plus 技术栈,基于单体模块化架构设计。

📁 项目目录结构

server/
├── surveyking-dependencies/ # Maven 依赖版本管理
│ └── pom.xml # 统一依赖版本定义
├── surveyking-framework/ # 技术框架封装
│ ├── surveyking-common/ # 通用组件
│ ├── surveyking-spring-boot-starter-web/ # Web 封装
│ ├── surveyking-spring-boot-starter-security/ # 安全认证
│ ├── surveyking-spring-boot-starter-mybatis/ # 数据库操作
│ ├── surveyking-spring-boot-starter-redis/ # Redis 缓存
│ ├── surveyking-spring-boot-starter-mq/ # 消息队列
│ ├── surveyking-spring-boot-starter-job/ # 定时任务
│ ├── surveyking-spring-boot-starter-file/ # 文件操作
│ ├── surveyking-spring-boot-starter-excel/ # Excel 处理
│ └── surveyking-spring-boot-starter-biz-*/ # 业务组件
├── surveyking-module-system/ # 系统功能模块
│ ├── surveyking-module-system-api/ # 系统模块API定义
│ └── surveyking-module-system-biz/ # 系统模块具体实现
├── surveyking-module-survey/ # 问卷功能模块
│ ├── surveyking-module-survey-api/ # 问卷模块API定义
│ └── surveyking-module-survey-biz/ # 问卷模块具体实现
├── surveyking-module-infra/ # 基础设施模块
│ ├── surveyking-module-infra-api/ # 基础设施API定义
│ └── surveyking-module-infra-biz/ # 基础设施具体实现
├── surveyking-module-report/ # 报表功能模块
│ ├── surveyking-module-report-api/ # 报表模块API定义
│ └── surveyking-module-report-biz/ # 报表模块具体实现
├── surveyking-server/ # 应用服务器
│ ├── src/main/java/
│ │ └── cn/surveyking/
│ │ └── SurveyKingApplication.java # 应用启动类
│ ├── src/main/resources/
│ │ ├── application.yml # 应用配置
│ │ ├── application-dev.yml # 开发环境配置
│ │ └── application-prod.yml # 生产环境配置
│ └── pom.xml # 服务器依赖配置
└── pom.xml # 父 POM 配置

🏗️ 分层架构设计

控制器层示例

@RestController
@RequestMapping("/api/v1")
public class SurveyController {

@Autowired
private SurveyService surveyService;

@GetMapping("/surveys")
public Result<PageResult<SurveyVO>> getSurveys(
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size) {
PageResult<SurveyVO> result = surveyService.getSurveys(page, size);
return Result.success(result);
}

@PostMapping("/surveys")
public Result<SurveyVO> createSurvey(@RequestBody SurveyCreateDTO dto) {
SurveyVO survey = surveyService.createSurvey(dto);
return Result.success(survey);
}
}

服务层示例

@Service
@Transactional(rollbackFor = Exception.class)
public class SurveyServiceImpl implements SurveyService {

@Autowired
private SurveyMapper surveyMapper;

@Override
public PageResult<SurveyVO> getSurveys(Integer page, Integer size) {
Page<Survey> pageObj = new Page<>(page, size);
Page<Survey> result = surveyMapper.selectPage(pageObj, null);

List<SurveyVO> surveys = result.getRecords().stream()
.map(this::convertToVO)
.collect(Collectors.toList());

return PageResult.<SurveyVO>builder()
.records(surveys)
.total(result.getTotal())
.build();
}
}

数据访问层示例

@Mapper
public interface SurveyMapper extends BaseMapper<Survey> {

List<Survey> selectByUserId(@Param("userId") String userId);

Long countByStatus(@Param("status") SurveyStatus status);
}

🎯 核心实体设计

实体类示例

@Data
@TableName("t_survey")
public class Survey {

@TableId(type = IdType.ASSIGN_ID)
private String id;

private String title;

private String description;

@Enumerated(EnumType.STRING)
private SurveyStatus status;

private String createdBy;

@TableField(fill = FieldFill.INSERT)
private LocalDateTime createdAt;

@TableLogic
private Boolean deleted;
}

下一步: 查看 系统配置 了解详细的配置说明。