mabatis-plus插件的使用和jar包下载

mabatis-plus自动导入bean和mapper包和相关类

1.mybatis_plus_2(2).jar包下载链接地址:https://pan.baidu.com/s/1KCtipFeBzonaGhLvY1DDJg

2.下载完之后导入工程,在pom.xml添加依赖:

<dependency>
  <groupId>org.mybatis.generator</groupId>
  <artifactId>mybatis-generator-core</artifactId>
  <version>1.3.4</version>
</dependency>

3.在resources下新建mybatis-generator-config XML文件:Batis_gen.xml,然后配置相关信息

<generatorConfiguration>
    <!-- !!!! Driver Class Path !!!! -->
    <classPathEntry location="mybatis_plus_2(2).jar包添加到工程的所在路径"/>
    <context id="context" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressAllComments" value="false"/>
            <property name="suppressDate" value="true"/>
        </commentGenerator>
        <!-- !!!! Database Configurations !!!! 数据库的相关配置-->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/db1106"
                        userId="root"
                        password="123456"/>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>
        <!-- !!!! Model Configurations !!!! targetPackage=实体类所在的包名
                                            targetProject=实体类所在工程的路径-->
        <javaModelGenerator targetPackage="com.demo.bean" 
                            targetProject="./src/main/java">
            <property name="enableSubPackages" value="false"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
       
<!-- !!!! Mapper XML Configurations !!!! -->
        <sqlMapGenerator targetPackage="com.demo.mapper" 
                        targetProject="./src/main/java">
            <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>
        <!-- !!!! Mapper Interface Configurations !!!! -->
        <javaClientGenerator targetPackage="com.demo.mapper" 
                            targetProject="./src/main/java" 
                            type="XMLMAPPER">
            <property name="enableSubPackages" value="false"/>
        </javaClientGenerator>
        <!-- !!!! Table Configurations !!!!数据库对应的表名:可以写多个-->
        <table tableName="student" 
               enableCountByExample="false" 
               enableDeleteByExample="false" 
               enableSelectByExample="false"
               enableUpdateByExample="false"/>
    </context>
</generatorConfiguration>

4.写个测试类去实现:MainTest.

    注意:此代码只能执行一次,为了防止意外,执行完之后可以删除

public class MainTest {
    public void generator() throws Exception{
        List<String> warnings = new ArrayList<String>();
        boolean overwrite = true;
        //指定 逆向工程配置文件
        File configFile = new File("src/main/resources/Batis_gen.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
                callback, warnings);
        myBatisGenerator.generate(null);
    }

    public static void main(String[] args) throws Exception {
        try {
            MainTest generatorSqlmap = new MainTest();
            generatorSqlmap.generator();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

5.到此结束,查看是否自动生成bean和mapper及相关类

 

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页