五、实战脚手架搭建-逆向生成代码和配置mybatis

5 实战脚手架搭建-逆向生成代码和配置mybatis

5.1 新建 generatorConfig.xml




    
    

    
    
    
        
        
        
        
        

        

        
        
            
             
        

        
        
        
        
            
            
        

        
        
            
            
        
        
        
            
        
        
        
            
        


        
            
            
            
        

generatorConfig.xml的头文件http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd报红

解决方案:左边有红色小灯泡,点击Fetch external resource即可解决

[图片上传失败...(image-7a28ca-1587796190552)]

5.2 pom 添加相应 plugin

            
            
            
                org.mybatis.generator
                mybatis-generator-maven-plugin
                1.3.5
                
                    src/main/resources/generatorConfig.xml
                    true
                    true
                
                
                    
                        deploy
                        Generate MyBatis Artifacts
                        
                            generate
                        
                    
                
                
                    
                        org.mybatis.generator
                        mybatis-generator-core
                        1.3.5
                    
                
            

5.3 运行 mybatis-generator

1567518616933.png

5.4 配置 mybatis

  • 修改 CompanyFrameApplication

    package com.yingxue.lesson;
    
    import org.mybatis.spring.annotation.MapperScan;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    @MapperScan("com.yingxue.lesson.mapper")
    public class CompanyFrameApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(CompanyFrameApplication.class, args);
        }
    
    }
    
    
  • 修改 application.properties

    #加入以下配置 对应生成 mapper.xml 的路径
    mybatis.mapper-locations=classpath:mapper/*.xml
    
  • 修改 application.yml

    #加入以下配置 对应生成 mapper.xml 的路径
    mybatis:
      mapper-locations: classpath:mapper/*.xml
    

你可能感兴趣的:(五、实战脚手架搭建-逆向生成代码和配置mybatis)