SqlMapConfig.xml---在spring配置文件中自动加载的mybatis文件

转自:http://blog.csdn.net/snn1410/article/details/7848121,另,这位兄台写的也很详细:http://my249645546.iteye.com/blog/1416344

<?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>
 <settings>
  <!-- 这个配置使全局的映射器启用或禁用缓存 -->
  <setting name="cacheEnabled" value="true" />
  <!-- 允许 JDBC 支持生成的键。需要适合的驱动。如果设置为 true 则这个设置强制生成的键被使用,尽管一些驱动拒绝兼容但仍然有效(比如 Derby) -->
  <setting name="useGeneratedKeys" value="true" />
  <!-- 配置默认的执行器。SIMPLE 执行器没有什么特别之处。REUSE 执行器重用预处理语句。BATCH 执行器重用语句和批量更新  -->
  <setting name="defaultExecutorType" value="REUSE" />
  <!-- 全局启用或禁用延迟加载。当禁用时,所有关联对象都会即时加载。 -->
  <setting name="lazyLoadingEnabled" value="true"/>
  <!-- 设置超时时间,它决定驱动等待一个数据库响应的时间。  -->
  <setting name="defaultStatementTimeout" value="25000"/>
 </settings>
 
 <!-- 别名配置 -->
 <typeAliases>
       <typeAlias alias="Renyuan" type="com.haso.bscs.po.Renyuan" />---po对象
       <typeAlias alias="LoginView" type="com.haso.bscs.view.LoginView" /> --view对象
 </typeAliases>
 
 <!-- 指定映射器路径 -->
 <mappers>
  <mapper resource="com/haso/bscsserver/dao/RenyuanDao.xml" />

  <mapper resource="com/haso/bscsserver/dao/CardPersonMessageDao.xml"/>

  <mapper resource="com/haso/bscsserver/dao/InfoDao.xml" />

        <mapper resource="com/haso/bscsserver/dao/VersionDao.xml" /> 
       
        <mapper resource="com/haso/bscsserver/dao/CommvarsDao.xml" />
       
         <mapper resource="com/haso/bscsserver/dao/TestDao.xml" />
         <mapper resource="com/haso/bscsserver/dao/RizhiDao.xml" />
       
 </mappers>
</configuration>

 

 

RenyuanDao.xml

************************************************************************************************************************

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 这里namespace必须是接口的路径,不然要运行的时候要报错 “is not known to the MapperRegistry”-->
<mapper namespace="com.haso.bscsserver.dao.RenyuanDao">
 <!-- 这里的id必须和接口中的方法名相同,不然运行的时候也要报错 -->
 <!-- <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/>  -->
 <cache type="org.mybatis.caches.ehcache.EhcacheCache"/> 
    <parameterMap type="LoginView" id="parameterLoginMap">
     <parameter property="name"/>
     <parameter property="usrpwd"/>
     <parameter property="ime"/>
     <parameter property="sim"/>
 </parameterMap>
 
    <parameterMap type="renyuanConditionView" id="parameterRenyuanMap">
        <parameter property="id"/>
     <parameter property="orginalPass"/>
     <parameter property="pass"/>
    </parameterMap>
     <parameterMap type="renyuanLocationView" id="parameterLocation">
        <parameter property="id"/>
     <parameter property="nowlat"/>
     <parameter property="nowlng"/>
     <parameter property="nowlocation"/>
    </parameterMap>
 <resultMap  type="renyuanView" id="resultRenyuanViewMap" >
     <result property="id"/>
     <result property="name"/>
     <result property="sim"/>
     <result property="ime"/>
     <result property="usrpwd"/>
     <result property="longtitude"/>
     <result property="latitude"/>
     <result property="beizhu"/>
     <result property="tel"/>
     <result property="email"/>
     <result property="username"/>
     <result property="nowlat"/>
     <result property="nowlng"/>
     <result property="nowlocation"/>
 </resultMap>
 
     <resultMap  type="Renyuan" id="resultRenyuanMap" >
     <result property="id"/>
     <result property="name"/>
     <result property="sim"/>
     <result property="ime"/>
     <result property="usrpwd"/>
     <result property="longtitude"/>
     <result property="latitude"/>
     <result property="beizhu"/>
     <result property="tel"/>
     <result property="email"/>
      <result property="username"/>
      <result property="nowlat"/>
     <result property="nowlng"/>
     <result property="nowlocation"/>
 </resultMap>
 <select id="findEntityById" resultMap="resultRenyuanMap" parameterType="int" useCache="true">
     SELECT *
     FROM renyuan
     WHERE id=#{id}
 </select>     
 
 <select id="findAllList" resultMap="resultRenyuanMap" useCache="true">
  select * from renyuan
 </select>
    
 <select id="findEntityByUnique"   resultMap="resultRenyuanMap"  parameterMap="parameterLoginMap">
  select * from renyuan where name=#{name} and usrpwd=#{usrpwd} and ime=#{ime} and sim=#{sim}
 </select>
 
 <select id="isOriginalPass"  parameterMap="parameterRenyuanMap" resultMap="resultRenyuanViewMap" useCache="true">
      select id,
             name,
             sim,
             ime,
             usrpwd,
             longtitude,
             latitude,
             beizhu,
             tel,
             email,
             username
          from renyuan
          where usrpwd = #{orginalPass} and id = #{id}
 </select>
 
 <update id="updatePassword" parameterMap="parameterRenyuanMap">
 
     update renyuan
          set usrpwd = #{pass}
          where id = #{id}
   
 </update>
 <update id="updateNowlocation" parameterMap="parameterLocation">
 
     update renyuan
          set nowlat = #{nowlat}
          ,nowlng = #{nowlng}
          ,nowlocation = #{nowlocation}
          where id = #{id}
   
 </update>
</mapper>

你可能感兴趣的:(SqlMapConfig.xml---在spring配置文件中自动加载的mybatis文件)