maven
1.maven的父工程一般都是一个pom文件,它本身并不能导入对应的jar包,继承它的子类也需要自己导入jar包,这是可以直接引入父亲maven包的版本。
2.在MySQL 5.6的版本上,优化器在遇到order by limit语句的时候,做了一个优化,即使用了priority queue。使用 priority queue 的目的,就是在不能使用索引有序性的时候,如果要排序,并且使用了limit n,那么只需要在排序的过程中,保留n条记录即可,这样虽然不能解决所有记录都需要排序的开销,但是只需要 sort buffer 少量的内存就可以完成排序。之所以5.6出现了第二页数据重复的问题,是因为 priority queue 使用了堆排序的排序方法,而堆排序是一个不稳定的排序方法,也就是相同的值可能排序出来的结果和读出来的数据顺序不一致。5.5 没有这个优化,所以也就不会出现这个问题。
解决方法:在order by字段后面+primay key
3.mysql的 text不能有默认值
4.mybatis注解使用自增key返回主键的值
@Options(useGeneratedKeys = true, keyProperty = "id")
5.数据库primay key不需要构建联合索引
如id = ? and is_del = ? 之需要构建is_del索引就可以了。因为 pk默认就是索引
6.如何打日志
https://juejin.cn/post/6844903781977554958
7.mybatis注解的坑
最后的条件分格加\n空格
idea
- idea中经常遇见lombok插件导致build失败的问题,目前常见解决的方法
- 清除idea的缓存
- 更新idea的版本
- 更新lombok插件
- 插件版本问题
- 新建idea项目,出现报错直接mvn idea:idea
mybatis异常总结
MyBatisSystemException
提示信息:
nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'bunldeId' in 'class com.tal.competition.domain.choice.MultipleChoiceAnswer'
错误原因:
sql语句写错,bunldeId应该为bundleId
SQLSyntaxErrorException
提示信息:
Unknown column 'city_code' in 'field list'; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: Unknown column 'city_code' in 'field list'
错误原因:
sql语句中包含数据库中不存在字段
提示信息:
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 '' at line 1
错误原因:
这种情况可能是foreach里面的数组为空
SQLIntegrityConstraintViolationException
提示信息:
Column 'bundle_id' cannot be null; nested exception is java.sql.SQLIntegrityConstraintViolationException: Column 'bundle_id' cannot be null
错误原因:
数据库的某字段约束设置为不能为空,但是sql语句插入的数据为空