QA项目的开发
开发工具
MYSQL数据库
Tomcat应用服务器
Git:版本管理
IDEA
Navicat Premium 12:数据库客户端
PDMan:建模工具
Postman:接口调试工具
开发环境
mysql 5.7.31
jdk 11.0.8
springboot 2.2.4
maven
redis
knife4j
git 2.19.1
mybatis
用到的技术栈
springmvc、springboot
mysql数据库、redis缓存、knife4j API接口、mybatis持久层框架
部分错误记录
错误:Could not set parameters for mapping 解决:xml中不能-注释
错误:Column count doesn't match value count at row 1 解决:mybatis动态sql语句,
<if test="answer.id != null">Id,</if>
<if test="answer.id != null ">#{answer.id},</if>这里的test都是参数,误将第一个设为数据库表的字段。
错误:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'id, 解决:出现少逗号
警告: Field injection is not recommended 解决:spring 4.0开始就不推荐使用属性注入,改为推荐构造器注入和setter注入。
项目过程
1.数据库
1.1运行sql建表
1.2建模
表(USER,ANSWER,DONATE,QUESTION)
表(MESSAGE USER1 USER2)
1.3添加字段flag用做逻辑删除,默认值1
2.项目创建
(项目目录结构)
2.1 创建springboot项目,引入依赖
2.2 对应数据库的各个表,创建所有对象的实体类
2.3 使用mybatis操作数据库,做所有表的CRUD
2.3.1 配置xml,动态sql语句
2.3.2 mapper单元测试
2.4 knife4j配置
2.4.1 创建SwaggerConfiguration配置api文档
2.5 service controller
2.5.1创建工具类HttpResult,Http结果封装
2.5.2 service接口 -> serviceImpl -> controller
2.6 postman测试
2.7 knife4j接口测试
2.8 redis缓存
2.8.1 创建工具类JsonUtils用于处理json数据
2.8.2 Controller中使用redis,先查询,有则取出使用,没有则查询数据库并将数据导入redis
2.9 项目上传gitee