欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

数据库索引问问题,主键重复

程序员文章站 2022-03-03 20:03:25
...

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
相关标签: java javascript