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