记项目中出现的数据库若干问题和注意事项

1.主键重复
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’解决:数据库索引问问题,主键重复

2.解决异常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>

3.高版本数据库,application.yml文件中url配置错误解决:需添加serverTimezone时区url: jdbc:mysql://127.0.0.1:3306/agg_pay?allowMultiQueries=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
完整配置

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

4.配置mybatis:注意mapper-locations: classpath:mapper/*Mapper.xml与项目中对应

mybatis:
  mapper-locations: classpath:mapper/*Mapper.xml
  type-aliases-package: com.ggit.pay.entity
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值