mybatis main configuration file SqlMapConfig.xml

Configuring Content:

  Content and sequence configured SqlMapConfig.xml

    -properties (attribute)
      --property
    -settings (global parameters)
      --setting
    -typeAliases (typedef)
      --typeAliase
      --package
    -typeHandlers (processor type)
    -objectFactory (Object Factory)
    -plugins (plug)
    -environments (environmental collection property objects)
      --environment (Object environment sub-attribute)
        --- the transactionManager (transaction management)
        --- the dataSource (data source)
    -mappers (mapper)
      --mapper
      --package

properties (attributes):

  When using the properties tab to configure, we can specify the attributes configured in two ways

    The first:

      <properties>
        <property name="jdbc.driver" value="com.mysql.jdbc.Driver"/>
        <property name="jdbc.url" value="jdbc:mysql://localhost:3306/user"/>

        <property name="jdbc.username" value="root"/>
        <property name="jdbc.password" value="root"/>
      </properties>

    The second: the definition jdbcConfig.properties file in the classpath

        jdbc.driver=com.mysql.jdbc.Driver
        jdbc.url=jdbc:mysql://localhost:3306/user
        jdbc.username=root
        jdbc.password=root

      <- Configuration database connection!
        Resource attribute: Specifies the location of the profile properties, under the required configuration file must classpath
          Resource = "jdbcConfig.properties"
        URL properties:
          the URL: Uniform the Resource Locator Uniform Resource Locator
            http: // localhost: 8080 / mystroe / CategoryServlet uRL
             protocol host port URI of the
          URI of the: uniform resource identifier uniform resource identifier
            / mystroe / CategoryServlet
            it is only in the web application to locate a resource path
      ->
      <url = the Properties File: / //D:/IdeaProjects/mybatis/src/main/resources/jdbcConfig.properties ">
      </ Properties>

   dataSource tag becomes a reference to the above configuration

    <dataSource type="POOLED">
      <property name="driver" value="${jdbc.driver}"/>
      <property name="url" value="${jdbc.url}"/>
      <property name="username" value="${jdbc.username}"/>
      <property name="password" value="${jdbc.password}"/>
    </dataSource>

typeAliases (type alias)

  Custom Alias:

    <typeAliases>
      <-! single alias definition ->
      <typeAlias Alias = "User" type = "com.fgy.domain.User" />
      <-! bulk alias definition, the entire package at the scanning type, alias class name (first letter can be upper or lower case) ->
      <package name = "com.fgy.domain" />
      <package name = "other packet" />
    </ typeAliases>

by mappers (mapper)

  <mapper resource=" " />

    With respect to the use of the resource class path
    , such as: <mapper resource = "com / fgy / dao / UserDaoMapper.xml" />

  <mapper class=" " />

    Use mapper interface class path
    as: <mapper class = "com.fgy.dao.UserDao" />
    Note (using xml development mode): This method requires an interface mapper and mapper mapping file name of the same name, and in the same directory in.

  <package name=""/>

    All mapper registers the specified interface in the package
    , such as: <package name = "com.fgy.mybatis.mapper" />
    Note (using xml development mode): This method requires an interface mapper and mapper mapping file name of the same name, and in the same directory.

Guess you like

Origin www.cnblogs.com/roadlandscape/p/12290894.html