springboot使用mybatis和默认数据库操作

问题:

1. SpringBoot整合Mybatis扫描不到Mapper的问题

错误信息:

***************************
APPLICATION FAILED TO START
***************************

Description:

Field appUserDao in com.example.webtest.service.AppUserService required a bean of type 'com.example.webtest.mapper.AppUserDao' that could not be found.

The injection point has the following annotations:
	- @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.example.webtest.mapper.AppUserDao' in your configuration.

错误原因
BaseMapper接口被系统扫描到。可能是未指定@MapperScan的路径或者指定的路径包含BaseMapper路径。
解决方法
将BaseMapper路径和MapperScan扫描路径分隔开,然后@MapperScan直接指向自定义Mapper路径。如图,@MapperScan设置为"com.example.webtest"就会出错:springboot使用mybatis和默认数据库操作
参考:https://blog.csdn.net/sinat_34979383/article/details/78674433

2. jdbc的类名废弃

错误信息:

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

解决方法:
springboot使用mybatis和默认数据库操作
参考:https://blog.csdn.net/weixin_42323802/article/details/82500458

3.语法错误或表设计错误

错误信息:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '***'

错误原因及解决:

  1. 语法错误。如果是自己写SQL语句,注意仔细检查是否有语法错误。我这里未自己写,使用的默认语句,所以排除语法错误。
  2. 表设计错误。
    注意表名的命名规则及不可使用的符号。如符号’-’。
    注意主键(id)自增设置,否则在添加一条新数据(无id)时,会提示主键没有默认值。java.sql.SQLException: Field 'id' doesn't have a default value

相关文章:

  • 2022-03-08
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-21
猜你喜欢
  • 2022-12-23
  • 2022-01-10
  • 2021-08-19
  • 2022-12-23
  • 2021-09-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案