SpringBoot使用mybatis插件自动创建逆向工程

什么是MyBatis逆向工程?

在传统的方式中,连接数据库并且对数据库增删改查等操作都需要程序员自己去编写,而这部分代码普遍都是死的,对于开发速度、效率来说都比较落后。所以我们就需要借助工具来简化我们的操作,从而提高我们的工作效率,同时,熟练使用MyBatis创建逆向工程也是程序员的一门必修课。

创建逆向工程一般分为两种,一种手动编写,另一种是利用MyBatis官方提供的插件进行自动创建,这里我主要说一下插件的创建方法,我使用的是SpringBoot2.1,工具是sts

1.点击Help-->Eclipse Markeptlace进入sts插件库搜索mybatis,并且安装

我这里已经安装,未安装就显示install,安装后按照提示重启即可SpringBoot使用mybatis插件自动创建逆向工程_第1张图片

2.修改pom.xml,导入mybatis依赖

    
		
			com.oracle
			ojdbc6
			11.2.0.3
		
		
		
        
            org.mybatis.generator
            mybatis-generator-core
            1.3.7
        

3.创建generatorConfig.xml逆向工程文件,并且配置该文件




  
  
  
  
  
  
  
  
  
    
    
    
       
			
		
    
    
    
    	
        
        
        
    
    
    
    
    	
        
    
    
    
    
    	
        
    
    
    
    

Tips:配置application.properties,定义数据库信息

#数据源配置 
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.username=ht
spring.datasource.password=hting
spring.datasource.url=jdbc:oracle:thin:@localhost:1521/XE

spring.thymeleaf.prefix=classpath:/templates/

#*mapper.xml文件对应的位置
mybatis.mapper-locations=classpath*:/com/zfsh/mappers/*Mapper.xml

4.在generatorConfig.xml配置文件中点击Run As---->Run MyBatis Gengerator运行插件

看到控制台输出build Success即表示创建成功

你可能感兴趣的:(SpringBoot)