美文网首页
SpringBoot+Mybatis web项目常见bug

SpringBoot+Mybatis web项目常见bug

作者: 取名废同学 | 来源:发表于2019-01-11 15:51 被阅读0次

平时用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 iscom.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文件写法:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.demo.mapper.UserMapper">
<resultMap id="userMap" type="com.example.demo.entity.User">
    <id property="id" column="id"/>
    <result property="username" column="username" />
    <result property="password" column="password" />
</resultMap>

<select id="findById" resultMap="userMap">
select * from user where id=#{id}
</select>
</mapper>

相关文章

  • SpringBoot+Mybatis web项目常见bug

    平时用eclipse比较多,自学springboot的时候转用idea,所以有些操作不是很熟悉,在这里记录一下遇到...

  • WEB测试常见BUG

    1、翻页 翻页时,没有加载数据为空,第二页数据没有请求 翻页时,重复请求第一页的数据 翻页时,没有图片的内容有时候...

  • 常见的BUG_BUG预防

    常见的BUG_BUG预防 WEB产品常见问题如下: 1、页面显示:不同的分辨率下测试 2、兼容不同的浏览器:主流浏...

  • 项目常见bug收集

    1、https页面加载http资源导致在IOS下报错的问题 解决:属于跨域范畴,要加载相同协议的资源。如:页面引入...

  • 移动web端常见bug

    本文是摘录整理了移动端常见的一些bug以及解决方案 点击样式闪动 Q: 当你点击一个链接或者通过Javascrip...

  • 2019-10-15 Java Web常见漏洞分析

    目录 Java vs PHP Java Web的常见概念 Java Web项目的目录结构 Servlet JSP(...

  • SpringBoot+Mybatis bug记录

    1、 (class使其居中) 2、ajax要引入jQuery库 3、前端传日期,后台先用String接收,再转...

  • 微不足道之第三篇:关于Web测试

    今天谈谈关于Web项目bug修复后上线流程和线上监控的思考。 首先,当bug在测试环境修复并验证通过,让研发打包...

  • SpringBoot java.lang.ClassCastEx

    最近项目使用springboot构建web工程 项目中大量使用反射解约开发时间,开始发现这个BUG的时候。 以为反...

  • BS框架增删改查开发步骤以及注解使用

    背景:项目框架使用springboot+mybatis 1、使用maven插件生成entity和mapper文件 ...

网友评论

      本文标题:SpringBoot+Mybatis web项目常见bug

      本文链接:https://www.haomeiwen.com/subject/cipxdqtx.html