首页 > 代码库 > 02_MyBatis项目结构,所需jar包,ehcache.xml配置,log4j.properties,sqlMapConfig.xml配置,SqlMapGenerator.xml配置

02_MyBatis项目结构,所需jar包,ehcache.xml配置,log4j.properties,sqlMapConfig.xml配置,SqlMapGenerator.xml配置


  1. 项目结构(所需jar包,配置文件)

技术分享

技术分享

技术分享

  1. sqlMapConfig.xml的配置内容如下:

<?xmlversion="1.0"encoding="UTF-8"?>

<!DOCTYPEconfiguration

PUBLIC"-//mybatis.org//DTD Config 3.0//EN"

"http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>

   <!--开启延迟加载 -->

   <settings>

      <!--全局的延迟加载的开关必须要开启 -->

      <settingname="lazyLoadingEnabled"value="true"/>

      <!--积极加载设置成false -->

       <settingname="aggressiveLazyLoading"value="false"/>

       <!--开启二级缓存,缓存中只要是需要配置的针对的都是二级缓存 -->

       <settingname="cacheEnabled"value="true"/>

   </settings>

   

   <typeAliases>

      <!--

          自定义别名:

             type:要定义别名的数据类型

             alias:别名的内容

       -->

       <!--

          非自定义别名:

             jdk中的所用的类的别名直接只用类名即可(不区分大小写)

             如果是基本数据类型的包装类还可以使用基本数据类型的名字

        -->

      <typeAliastype="com.rl.model1.QueryCondition"alias="qc"/>

      <typeAliastype="com.rl.model1.Person"alias="person"/>

   </typeAliases>

   

   <!--数据库的环境的配置 -->

   <environmentsdefault="development">

      <environmentid="development">

          <transactionManagertype="JDBC"/>

          <dataSourcetype="POOLED">

             <propertyname="driver"value="com.mysql.jdbc.Driver"/>

             <propertyname="url"value="jdbc:mysql://localhost:3306/mybatis"/>

             <propertyname="username"value="root"/>

             <propertyname="password"value="123456"/>

          </dataSource>

      </environment>

   </environments>

   

   <!--集中管理表的映射文件 -->

   <mappers>

      <mapperresource="com/rl/mapper/PersonTestMapper.xml"/>

      <mapperresource="com/rl/mapper/PersonMapper.xml"/>

      <mapperresource="com/rl/mapper/RoleMapper.xml"/>

      <mapperresource="com/rl/mapper/OrdersMapper.xml"/>

      <mapperresource="com/rl/mapper/OrderDetailMapper.xml"/>

   </mappers>

</configuration>

  1. sqlMapGenerator.xml的配置如下:

<?xmlversion="1.0"encoding="UTF-8"?>

<!DOCTYPEgeneratorConfiguration PUBLIC"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN""http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

<generatorConfiguration>

   <!--指定mysql的驱动包的路径,不要放在中文路径下 -->

   <classPathEntrylocation="E:\MyEclipse10\MyBatis\lib\mysql-connector-java-5.0.8-bin.jar"/>

   <!--配置数据源和生成的代码所存放的位置 -->

   <contextid="context1">

      <commentGenerator>

          <!--去除自动生成的注释 -->

          <propertyname="suppressAllComments"value="true"/>

      </commentGenerator>

      

      <jdbcConnection

          driverClass="com.mysql.jdbc.Driver"

          connectionURL="jdbc:mysql://127.0.0.1:3306/mybatis"

          userId="root"

          password="123456"/>

      <!--所生成的实体类的位置默认资源包src -->

      <javaModelGeneratortargetPackage="com.rl.model1"

          targetProject="mybatis0420"/>

      <!--所生成的sqlMap的影射文件的位置,默认资源包src -->

      <sqlMapGeneratortargetPackage="com.rl.mapper"

          targetProject="mybatis0420"/>

 

      <!--为哪些表生成代码 tableName:表名 schema:不用填写,其余属性是禁用例子查询的生成 -->

      <tableschema=""tableName="role"enableCountByExample="false"

          enableUpdateByExample="false"enableDeleteByExample="false"

          enableSelectByExample="false"selectByExampleQueryId="false"/>

          

      <tableschema=""tableName="person_role"enableCountByExample="false"

          enableUpdateByExample="false"enableDeleteByExample="false"

          enableSelectByExample="false"selectByExampleQueryId="false"/>

   </context>

</generatorConfiguration>

  1. log4j.properties的配置内容如下:

log4j.rootLogger=DEBUG,Console

#Console

log4j.appender.Console=org.apache.log4j.ConsoleAppender

log4j.appender.Console.layout=org.apache.log4j.PatternLayout

log4j.appender.Console.layout.ConversionPattern=%d[%t]%-5p[%c]-%m%n

log4j.logger.java.sql.ResultSet=INFO

log4j.logger.org.apache=INFO

log4j.logger.java.sql.Connection=DEBUG

log4j.logger.java.sql.Statement=DEBUG

log4j.logger.java.sql.PreparedStatement=DEBUG

  1. ehcache.xml的配置内容如下:

<ehcachexmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="../config/ehcache.xsd">

 

   <diskStorepath="java.io.tmpdir"/>

   <defaultCache

           maxElementsInMemory="10000"

           eternal="false"

           timeToIdleSeconds="120"

           timeToLiveSeconds="120"

           maxElementsOnDisk="10000000"

           diskExpiryThreadIntervalSeconds="120"

           memoryStoreEvictionPolicy="LRU">

       <persistencestrategy="localTempSwap"/>

   </defaultCache>

</ehcache>

 

02_MyBatis项目结构,所需jar包,ehcache.xml配置,log4j.properties,sqlMapConfig.xml配置,SqlMapGenerator.xml配置