数据库索引问问题,主键重复
There was an unexpected error (type=Internal Server Error, status=500).### Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry ‘1’ for key ‘PRIMARY’ ### The error may involve com.ggit.pay.mapper.UserMapper.insertUser-Inline ### The error occurred while setting parameters ### SQL: INSERT INTO test(id,userName,passWord) VALUES (?,?,? ) ### Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry ‘1’ for key ‘PRIMARY’ ; Duplicate entry ‘1’ for key ‘PRIMARY’; nested exception is java.sql.SQLIntegrityConstraintViolationException: Duplicate entry ‘1’ for key 'PRIMARY’解决:数据库索引问问题,主键重复
解决异常Error creating bean with name 'xxxxxController': Unsatisfied dependency expressed through field
解决:检查usermapper.xml的文件配置,特别是resultType和parameterType
<select id="findUserByName" resultType="java.util.HashMap">
SELECT * FROM test where id = #{id}
</select>
```javascript
<insert id="insertUser" parameterType="com.ggit.pay.entity.User"
keyProperty="id" useGeneratedKeys="true">
INSERT INTO test(id,userName,passWord)
VALUES (#{id},#{userName, jdbcType=VARCHAR},#{passWord, jdbcType=VARCHAR} )
</insert>
高版
本数据库,application.yml文件中url配置错误解决:需添加serverTimezone时区url: jdbc:mysql://127.0.0.1:3306/agg_pay?allowMultiQueries=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
完整配置
```java
mysql:spring:
datasource:
username: root
password: wshy0924
url: jdbc:mysql://127.0.0.1:3306/agg_pay?allowMultiQueries=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
driver-class-name: com.mysql.cj.jdbc.Driver
配置mybatis:注意mapper-locations: classpath:mapper/*Mapper.xml与项目中对应
mybatis:
mapper-locations: classpath:mapper/*Mapper.xml
type-aliases-package: com.ggit.pay.entity
推荐阅读
-
jdbc获取mysql、oracle数据库的表、字段、主键、唯一索引
-
数据库的几个概念:主键,外键,索引,唯一索引
-
数据库的几个概念:主键,外键,索引,唯一索引
-
面试|简单描述MySQL中,索引,主键,唯一索引,联合索引 的区别,对数据库的性能有什么影响(从读写两方面)
-
GBase 8s数据库主键约束、唯一约束和唯一索引的区别解析
-
GBase 8s数据库主键约束、唯一约束和唯一索引的区别解析
-
面试|简单描述MySQL中,索引,主键,唯一索引,联合索引 的区别,对数据库的性能有什么影响(从读写两方面)
-
如何理解数据库中的主键,外键以及索引
-
如何理解数据库中的主键,外键以及索引
-
高并发网站如何解决数据库主键自增的时候出现重复?