平时用eclipse比较多,自学springboot的时候转用idea,所以有些操作不是很熟悉,在这里记录一下遇到的一些bug及解决方案。
IDEA的一些便捷操作:
(1)Import某个类可用:alt+enter
(2)自动生成测试类,用junit测试,idea对着要进行测试的类/方法光标覆盖 ctrl+shift+t 选择create test class,勾选要测试的方法
一、【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.】
由于版本的问题,mysql5用的驱动url是com.mysql.jdbc.Driver,mysql6以后用的是com.mysql.cj.jdbc.Driver。版本不匹配便会报驱动类已过时的错误。
说明application.yml配置中应改为:
【driver-class-name: com.mysql.cj.jdbc.Driver】
二、【org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):】
首先,一般情况下要检查mapper文件的地址是否对应。
另外!!!IDEA对xml文件处理的方式不同.** mapper.xml文件需要放置在resource这个文件夹下.**
而eclipse只要mapper接口文件与mapper.xml放置在同一平级目录就行。
三、JDBC连接Mysql6 com.mysql.cj.jdbc.Driver, 需要指定时区serverTimezone,否则会报如下错误,
【 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException:
Cannot create PoolableConnectionFactory (The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.)WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.】
一定要加上?characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false
==>【url: jdbc:mysql://localhost:3306/smtest?characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false】
四、Mybais的XXXmapper文件头写错,导致无法读取mapper文件标签内容
标准的mapper文件写法: