本文共 292 字,大约阅读时间需要 1 分钟。
一 报错信息
org.springframework.dao.DuplicateKeyException: Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry ‘hm’ for key ‘username’ 二 分析原因 因为表中主键字段一般都设置了唯一约束条件,插入时与已有数据主键字段相同时就会产生错误信息。 三 解决办法 主键的内容不要设置太简单,比如可以用MD5加密后的字符串,,加入时间和其他一些独有信息生成主键更不容易重复哦!转载地址:http://nalwi.baihongyu.com/