[Mybatis]3.配置优化


1.properties优化

1.在resources文件夹下新建db.properties文件

driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/mybatis1?useUnicode=true&characterEncoding=UTF-8
username=root
password=123456

2.在mybati-config.xml中添加


  

resource代表引入的配置文件
内部的 为自定义的属性配置(重名时优先使用配置文件)

3.修改environment

    
        
            
            
                
                
                
                
            
        
    

2.别名

为了解决mapper.xml中完全限定名的冗余,可以在配置文件中设置别名。
1.指定别名


   

2.指定某个包,自动扫描javaBean


  

别名为类名
3.使用注解
@Alias("user")
优先使用注解的别名

3.设置(settings)插件(plugins) 等

https://mybatis.org/mybatis-3/zh/configuration.html