Mybatis-Plus 逆向工程

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.DbType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

/**
 * mybatisplus 的逆向工程
 * @author 25395
 *
 */
public class MyBatisGenerator {
	
	public static void main(String[] args) {
		 // 全局配置
        GlobalConfig gc = new GlobalConfig();
        gc.setOutputDir("D:\\dev\\stsSpace\\springboot-mybatisplus\\src\\main\\java");
        gc.setFileOverride(true);//文件覆蓋
        gc.setActiveRecord(true);// 不須要ActiveRecord特性的請改成false
        gc.setEnableCache(false);// XML 二級緩存
        gc.setBaseResultMap(true);// XML ResultMap
        gc.setBaseColumnList(true);// XML columList
        gc.setAuthor("liyhu");
        gc.setServiceName("%sService");//去掉前綴I
        
        // 數據源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setDbType(DbType.MYSQL);
        dsc.setDriverName("com.mysql.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("1234");
        dsc.setUrl("jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8");
        
     // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setInclude("dept");
        strategy.setNaming(NamingStrategy.underline_to_camel);//下劃線轉駝峯命名
        
     // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent("com.example.demo");
        pc.setMapper("mapper");
        pc.setEntity("bean");
        pc.setXml("mapper.xml");
        pc.setService("service");
        pc.setController("controller");
        
         
        //整合配置
        AutoGenerator mpg = new AutoGenerator();
        mpg.setGlobalConfig(gc);
        mpg.setDataSource(dsc);
        mpg.setStrategy(strategy);
        mpg.setPackageInfo(pc);      
        
        // 執行生成
        mpg.execute();
        System.out.println("生成完畢");
	}

}

依賴html

<dependencies>
		<dependency>
			<groupId>org.apache.velocity</groupId>
			<artifactId>velocity</artifactId>
			<version>1.7</version>
		</dependency>
	</dependencies>

分頁插件java

import com.github.pagehelper.PageInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MybatisplusCofig {
    
    @Bean
    public PageInterceptor pageInterceptor(){
        return new PageInterceptor();
    }
}
相關文章
相關標籤/搜索