mybatis配置文件模板(增删查改)

<?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" >
<mapper namespace="cn.jeeweb.modules.usergi.mapper.DimUserFileMapper" >
  <resultMap id="BaseResultMap" type="DimUserFileConf" >
    <result column="id" property="id" jdbcType="VARCHAR" />
    <result column="f_name" property="f_name" jdbcType="VARCHAR" />
    <result column="user_id" property="user_id" jdbcType="VARCHAR" />
    <result column="user_name" property="user_name" jdbcType="VARCHAR" />
    <result column="create_time" property="create_time" jdbcType="VARCHAR"/>
 
  </resultMap>
  <sql id="Base_Column_List" >
    d.id, 
    d.f_name, 
    d.user_id, 
    d.user_name, 
    d.create_time
  </sql>
  <select id="findListDimUserFileConf" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from dim_user_gi_file d  
    WHERE d.user_id= #{userid}  order by d.create_time desc
  </select>
  
   <!-- 导入文件 -->
   <insert id="addUserGiFile">
  	INSERT INTO dim_user_gi_file
 		 
 	values 
 		(#{id},#{f_name},#{user_id},#{user_name},#{create_time})
  </insert>
  
   <!--根据id 删除文件 -->  
  <delete id="deleteUserGiFile" parameterType="java.lang.String" >  
      delete from dim_user_gi_file
      where  id= #{id}  
  </delete>
  
   <!--根据 删除文件 -->  
  <delete id="doDeteleByName" parameterType="java.lang.String" > 
      delete from dim_user_gi_file
      where user_id=#{userid} and  f_name like  CONCAT('${f_name}','%' ) 
  </delete> 
  <!-- 模糊查找 -->
   <select id="findListDimUserFileList" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from dim_user_gi_file d  
    WHERE user_id=#{userid} and f_name like CONCAT('${f_name}','%' )
  </select>
  
</mapper>
<?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"/>
		
		<!-- 全局启用或禁用延迟加载。当禁用时,所有关联对象都会即时加载。 -->
		<setting name="lazyLoadingEnabled" value="true"/>
		
		<!-- 当启用时,有延迟加载属性的对象在被调用时将会完全加载任意属性。否则,每种属性将会按需要加载。 -->
		<setting name="aggressiveLazyLoading" value="true"/>
		
		<!-- 是否允许单条sql 返回多个数据集  (取决于驱动的兼容性) default:true -->
		<setting name="multipleResultSetsEnabled" value="true"/>
		
		<!-- 是否可以使用列的别名 (取决于驱动的兼容性) default:true -->
		<setting name="useColumnLabel" value="true"/>
		
		<!-- 允许JDBC 生成主键。需要驱动器支持。如果设为了true,这个设置将强制使用被生成的主键,有一些驱动器不兼容不过仍然可以执行。  default:false  -->
		<setting name="useGeneratedKeys" value="false"/>
		
		<!-- 指定 MyBatis 如何自动映射 数据基表的列 NONE:不隐射 PARTIAL:部分  FULL:全部  -->  
		<setting name="autoMappingBehavior" value="PARTIAL"/>
		
		<!-- 这是默认的执行类型  (SIMPLE: 简单; REUSE: 执行器可能重复使用prepared statements语句;BATCH: 执行器可以重复执行语句和批量更新)  -->
		<setting name="defaultExecutorType" value="SIMPLE"/>
		
		<!-- 使用驼峰命名法转换字段。 -->
		<setting name="mapUnderscoreToCamelCase" value="true"/>
		
		<!-- 设置本地缓存范围 session:就会有数据的共享  statement:语句范围 (这样就不会有数据的共享 ) defalut:session -->
        <setting name="localCacheScope" value="SESSION"/>
		
        <!-- 设置但JDBC类型为空时,某些驱动程序 要指定值,default:OTHER,插入空值时不需要指定类型 -->
        <setting name="jdbcTypeForNull" value="NULL"/>
		
	</settings>
	
	<!-- 插件配置 -->
	<plugins>
		 <!--
	     | 分页插件配置
	     | 插件提供二种方言选择:1、默认方言 2、自定义方言实现类,两者均未配置则抛出异常!
	     | overflowCurrent 溢出总页数,设置第一页 默认false
	     | optimizeType Count优化方式 ( 版本 2.0.9 改为使用 jsqlparser 不需要配置 )
	     | -->
	    <!-- 注意!! 如果要支持二级缓存分页使用类 CachePaginationInterceptor 默认、建议如下!! -->
		<plugin interceptor="com.baomidou.mybatisplus.plugins.PaginationInterceptor" />
		<!-- SQL 执行分析拦截器 stopProceed 发现全表执行 delete update 是否停止运行 
	    <plugin interceptor="com.baomidou.mybatisplus.plugins.SqlExplainInterceptor">
	        <property name="stopProceed" value="false" />
	    </plugin>-->
	    <!-- SQL 执行性能分析,开发环境使用,线上不推荐。 maxTime 指的是 sql 最大执行时长 -->
	    <!--  
	    <plugin interceptor="com.baomidou.mybatisplus.plugins.PerformanceInterceptor">
	        <property name="maxTime" value="2000" />
	        <property name="format" value="true" />
	    </plugin>
		-->
    </plugins>
	
</configuration>

猜你喜欢

转载自my.oschina.net/chendongj/blog/1618523