Mybaits配置文件


1.mybatis-config.xml

(mybatis核心配置文件xml)

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



    
    

    
    
        
        
          
        
    
       
    
        
        

        
        
        
    

	
	
		
			
			
				
				
				
				
			
		
	
    
	
		
		
	

2.db.properties(mysql5.7)

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/数据库名
#jdbc.url=jdbc:mysql://localhost:3306/数据库名?serverTimezone=GMT%2B8&useSSL=false
jdbc.username=root
jdbc.password=123456

3.MySQL8.0+的jdbc.properties的配置,以及相关解释

jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/数据库名?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
jdbc.username=root
jdbc.password=root

首先mysql JDBC URL格式如下:
jdbc:mysql://[host:port],[host:port]…/[database] ? [参数名1][=参数值1][&参数名2][=参数值2]…

相比于前版本,增加使用了:

useSSL=false&serverTimezone=UTC

关于userSSL=false : 原因5.5.45+, 5.6.26+ , 5.7.6+版本的MySQL如果未设置显式选项,则必须默认建立SSL连接,为了符合不使用SSL的现有应用程序,您可以将verifyServerCertificate属性设置为false,您需要通过设置useSSL=false显式禁用SSL,或者设置useSSL=true并提供用于服务器证书验证的信任库;

关于serverTimezone=UTC : 在设定时区的时候,如果设定serverTimezone=UTC,是全球标准时间,会比中国时间早8个小时,如果在中国,可以选择Asia/Shanghai或者Asia/Hongkong,例如:serverTimezone=Asia/Shanghai;

关于useUnicode=true:代表使用Unicode字符集,允许用户自己设定数据库编码

关于characterEncoding=utf-8: 在插入数据时,如果数据的编码类型与数据库的编码类型不一致时,如程序中使用GBK,而数据库的数据类型为utf8,会出现插入数据的字节的类型无法识别的问题。为了解决此问题,我们需要在URL上设置characterEncoding=utf-8。