springboot整合mybatis和mysql

添加依赖架包

    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>

    <!--mysql数据库-->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>

配置文件

在这里插入图片描述

扫描dao层

在这里插入图片描述

mybatis的xml文件响应头

xml文件配置响应头

<?xml version="1.0" encoding="UTF-8"?>

期间可能出现的问题

插件mybatis-generator 出现The server time zone value ‘�й���׼ʱ��’ is unrecogni的解决方法

原因
原因是因为使用了Mysql Connector/J 6.x以上的版本,然后就报了时区的错误

遇到的问题 servertime=UTC导致时间差8个小时

解决办法
在配置url的时候不能简单写成 :

jdbc:mysql://localhost:3306/mysql

而是要写成 :

jdbc:mysql://localhost:3306/mysql?serverTimezone=UTC

解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题

在这里插入图片描述
在这里插入图片描述
解决mysql数据库时区问题
The server time zone value ‘Öйú±ê׼ʱ¼ä’ is unrecognized or represents more than one time zone…

修改时区

第一种方法:
这种方法,不需要重启mysql,但是重启mysql,需要再次设置

set global time_zone = ‘+8:00’; ##修改mysql全局时区为北京时间,即我们所在的东8区
set time_zone = ‘+8:00’; ##修改当前会话时区
flush privileges; #立即生效

第二种方法

vim /etc/my.cnf ##在[mysqld]区域中加上

default-time_zone = ‘+8:00’

/etc/init.d/mysqld restart ##重启mysql使新时区生效

猜你喜欢

转载自blog.csdn.net/qq_43054241/article/details/100888785