读书笔记共享平台是一个基于现代Web技术构建的教育信息化解决方案。作为一名长期从事教育类系统开发的工程师,我发现传统纸质笔记存在三大痛点:一是物理载体易丢失损坏,二是难以实现多人协作与知识共享,三是检索效率低下。这个项目正是为了解决这些痛点而生。
平台采用前后端分离架构,后端使用SpringBoot2框架提供RESTful API服务,前端基于Vue3构建响应式用户界面。数据持久层采用MyBatis-Plus简化数据库操作,MySQL8.0作为关系型数据库存储核心数据。这种技术组合在当前企业级应用中非常典型,既保证了系统性能,又具有良好的可维护性。
提示:选择SpringBoot2而非SpringBoot3是考虑到国内企业当前的主流技术栈仍以Java8为主,确保项目能直接应用于大多数生产环境。
SpringBoot2框架的选择基于以下考量:
核心依赖配置示例(pom.xml关键片段):
xml复制<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.2</version>
</dependency>
</dependencies>
Vue3的组合式API相比选项式API具有明显优势:
典型组件结构:
code复制src/
├── components/
│ ├── NoteEditor.vue // 富文本编辑器组件
│ └── CommentList.vue // 评论列表组件
├── stores/
│ └── noteStore.js // Pinia状态管理
└── views/
└── NoteDetail.vue // 笔记详情页
采用JWT+Spring Security的安全方案,关键实现要点:
登录流程时序:
安全增强措施:
java复制// JWT配置类关键代码
@Configuration
public class JwtConfig {
@Value("${jwt.secret}")
private String secret;
@Bean
public JwtDecoder jwtDecoder() {
return NimbusJwtDecoder.withSecretKey(
new SecretKeySpec(secret.getBytes(), "HS256")
).build();
}
}
注意:务必设置合理的JWT过期时间(建议2小时),并使用HTTPS传输防止令牌泄露。
采用Quill.js集成方案,解决的技术难点包括:
核心配置:
javascript复制const quill = new Quill('#editor', {
modules: {
toolbar: [
['bold', 'italic'],
['link', 'image']
]
},
placeholder: '输入笔记内容...',
theme: 'snow'
});
基于MySQL全文索引的轻量级方案:
sql复制ALTER TABLE note_info
ADD FULLTEXT INDEX ft_idx (title, content)
WITH PARSER ngram;
搜索接口示例:
java复制@GetMapping("/search")
public Page<Note> searchNotes(
@RequestParam String keyword,
@PageableDefault Pageable pageable) {
return noteRepository.findByTitleContainingOrContentContaining(
keyword, keyword, pageable);
}
用户表(user_info)关键字段说明:
笔记表(note_info)优化点:
java复制// 错误示例:N+1查询问题
List<Note> notes = noteRepository.findAll();
notes.forEach(note -> {
User user = userRepository.findById(note.getUserId());
// ...
});
// 正确做法:使用JOIN查询
@Query("SELECT n FROM Note n JOIN FETCH n.user")
List<Note> findAllWithUser();
Docker Compose编排示例:
yaml复制version: '3'
services:
backend:
build: ./backend
ports:
- "8080:8080"
depends_on:
- mysql
frontend:
build: ./frontend
ports:
- "80:80"
mysql:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: root
SpringBoot Actuator关键端点:
现象:前端获取的JWT在5分钟后失效
排查过程:
解决方案:
javascript复制// 前端添加token自动刷新逻辑
axios.interceptors.response.use(response => {
return response;
}, error => {
if (error.response.status === 401) {
return refreshToken().then(() => {
return axios(error.config);
});
}
return Promise.reject(error);
});
采用乐观锁机制解决:
java复制@Entity
public class Note {
@Version
private Integer version;
// ...
}
public void updateNote(Note note) {
noteRepository.save(note); // 自动检查version
}
这个项目在实际开发中,最大的收获是要提前规划好状态管理方案。特别是在处理笔记的编辑状态时,我们最初没有做好设计,导致后来出现了数据同步问题。建议在类似项目中,尽早引入状态管理库(如Pinia),并制定严格的数据流规范。