• Mybatis生成


    Mybatis是ORM(Object/Relational/Mapping)类型的;

            对象/关系/映射

    Mybatis是数据持久化技术在对象模型和关系数据库之间建立起对应的关系,并且提供了一种机制叫JavaBean对象操作数据库表中数据。

    纯接口开发规范:

           1.映射文件的Mapper标签的namespace="类地址(全路径)"

           2.映射文件接口同包且同名

           3.映射文件中的SQLID与接口中的方法名相同

           4.映射文件中所需的参数与接口的参数相同

           5.返回值相同

    Mybatis用法:

     1.配置核心Xml文件    

    1.1:放入jar包或引入依赖  
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>3.4.0</version>
     </dependency>
     1.2:在src下创建XML文件,导入Mybatis协议,更改信息         
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE configuration
      PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
      "http://mybatis.org/dtd/mybatis-3-config.dtd">
    <configuration>
      <environments default="development">
        <environment id="development">
          <transactionManager type="JDBC"/>
          <dataSource type="POOLED">
            <property name="driver" value="驱动的地址"/>
            <property name="url" value="连接信息 例(jdbc:mysql://localhost:3306/库名)"/>
            <property name="username" value="数据库用户名"/>
            <property name="password" value="数据库密码"/>
          </dataSource>
        </environment>
      </environments>
      <mappers> ----映射文件集
        <mapper resource="org/mybatis/example/BlogMapper.xml"/>-----单个映射文件的地址
      </mappers>
    </configuration>
             

      2快速生成映射文件:

       2.1:将插件放入Eclipse下的dropins文件夹下

       2.2:将generatorConfig-base.xml文件放入src下

       2.3:修改generatorConfig-base.xml文件的驱动jar包地址

          修改数据库连接信息

          把文件地址改为当前项目名

          <table schema="" tableName="表名" ></table>有几个表写几个table标签

          右键generatorConfig-base.xml找到一个像飞镖的选项点击生成      

          报Project src does not exist错是因为没把文件地址改成当前项目名

       3代码生成:

         3.1:将下面的代码放入main方法configuartion倒最后一个包

         3.2:修改File中的信息

                      

    File configFile = new File(“src/generatorConfig.xml”);  

    List<String> warnings = new ArrayList<String>();
    boolean overwrite = true;
    File configFile = new File("generatorConfig.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);

      

                   

  • 相关阅读:
    多测师杭州拱墅校区肖sir_高级金牌讲师_项目讲解讲解和注意方式
    多测师杭州拱墅校区肖sir_高级金牌讲师_redis(参考)
    多测师杭州拱墅校区肖sir_高级金牌讲师_测试环境搭建问题
    【ArangoDb踩坑】新增Edge类型数据,from和to为document的_id
    firmware file rtl_bt/rtl8761b_fw.bin not found
    非递归前序遍历
    ELK & EFK
    边缘计算 controller提供的功能
    oran code go through
    hugepages configure
  • 原文地址:https://www.cnblogs.com/HQ0422/p/9993833.html
Copyright © 2020-2023  润新知