zoukankan      html  css  js  c++  java
  • MyBatis配置项--映射器(mappers)

    当MyBatis的行为已经由其他元素配置完成后,现在就要定义SQL映射语句了。但是首先需要告诉MyBatis到哪里去找到这些语句。

    java在自动查找这方面没有提供一个很好的方法,所以最佳的方式是告诉Mybatis到哪里去找映射文件。

    可以使用相对于类路径的资源引用,或完全限定资源定位符(包括file:///的URL),或类名和包名等。例如:

    <!-- 使用相对于类路径的资源引用 -->

    <mappers>

      <mapper resource="org/mybatis/builder/AuthorMapper.xml"/>

      <mapper resource="org/mybatis/builder/BlogMapper.xml"/>

      <mapper resource="org/mybatis/builder/PostMapper.xml"/>

    </mappers>

    <!-- 使用完全限定资源定位符(URL) -->

    <mappers>

      <mapper url="file:///var/mappers/AuthorMapper.xml"/>

      <mapper url="file:///var/mappers/BlogMapper.xml"/>

      <mapper url="file:///var/mappers/PostMapper.xml"/>

    </mappers>

    <!-- 使用映射器接口实现类的完全限定类名 -->

    <mappers>

      <mapper class="org.mybatis.builder.AuthorMapper"/>

      <mapper class="org.mybatis.builder.BlogMapper"/>

      <mapper class="org.mybatis.builder.PostMapper"/>

    </mappers>

    <!-- 将包内的映射器接口实现全部注册为映射器 -->

    <mappers>

      <package name="org.mybatis.builder"/>

    </mappers>

  • 相关阅读:
    Mybatis和Hibernate
    SpringMVC运行原理
    HTML中class属性里有多个属性值
    json对象(增加数据)
    Ajax请求
    <url-pattern>里的/和/*
    mysql忘记密码
    Eclipse无法正常连接mysql8.0.20
    a+1和&a+1
    可重入函数与不可重入函数
  • 原文地址:https://www.cnblogs.com/arrows/p/10341920.html
Copyright © 2011-2022 走看看