mybatis汇总

<sql id="Base_Column_List">
		id, user_id, comp_name, years, title
	</sql>
	<select id="selectByPrimaryKey" resultMap="BaseResultMap"
		parameterType="java.lang.Integer">
		select
		<include refid="Base_Column_List" />
		from t_job_history
		where id = #{id,jdbcType=INTEGER}
	</select>
	<insert id="insertSelective" parameterType="com.enjoylearning.mybatis.entity.TJobHistory">
		insert into t_job_history
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="id != null">
				id,
			</if>
			<if test="userId != null">
				user_id,
			</if>
			<if test="compName != null">
				comp_name,
			</if>
			<if test="years != null">
				years,
			</if>
			<if test="title != null">
				title,
			</if>
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="id != null">
				#{id,jdbcType=INTEGER},
			</if>
			<if test="userId != null">
				#{userId,jdbcType=INTEGER},
			</if>
			<if test="compName != null">
				#{compName,jdbcType=VARCHAR},
			</if>
			<if test="years != null">
				#{years,jdbcType=INTEGER},
			</if>
			<if test="title != null">
				#{title,jdbcType=VARCHAR},
			</if>
		</trim>
	</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.enjoylearning.mybatis.entity.TJobHistory">
		update t_job_history
		
		<set>
			<if test="userId != null">
				user_id = #{userId,jdbcType=INTEGER},
			</if>
			<if test="compName != null">
				comp_name = #{compName,jdbcType=VARCHAR},
			</if>
			<if test="years != null">
				years = #{years,jdbcType=INTEGER},
			</if>
			<if test="title != null">
				title = #{title,jdbcType=VARCHAR},
			</if>
		</set>
		where id = #{id,jdbcType=INTEGER}
	</update>
	<select id="heheya" resultType="map">
    SELECT c.name,MAX(CASE a.tname WHEN '婚假' THEN b.daytime ELSE 0 END ) 婚假,
	MAX(CASE a.tname WHEN '产假' THEN b.daytime ELSE 0 END ) 产假,
	MAX(CASE a.tname WHEN '病假' THEN b.daytime ELSE 0 END ) 病假,
	MAX(CASE a.tname WHEN '事假' THEN b.daytime ELSE 0 END ) 事假,
	MAX(CASE a.tname WHEN '暑假' THEN b.daytime ELSE 0 END ) 暑假 FROM t_mian_jia a,t_mian_zhong_jian b,t_mian c
	WHERE b.type=a.id AND b.mid = c.id GROUP BY c.name;
</select>

<insert id="insertForeach4Batch">
		insert into t_user (user_name, real_name,
		sex, mobile,email,note, position_id) 
		values
		<foreach collection="list" separator="," item="user">
			(
			#{user.userName,jdbcType=VARCHAR},
			#{user.realName,jdbcType=VARCHAR},
			#{user.sex,jdbcType=TINYINT}, 
			#{user.mobile,jdbcType=VARCHAR},
			#{user.email,jdbcType=VARCHAR},
			#{user.note,jdbcType=VARCHAR},
			#{user.positionId,jdbcType=INTEGER}
			)
		</foreach>
	
	
	</insert>

MYBATIS会根据Id,进行字段的合并,合理配置ID标签可以提高处理效率。

一级缓存:默认启用(一次会话sqlSession,一次数据库连接)
任何一次新增,删除,修改都会清空一级缓存。
二级缓存sqlSessionFactory(可以理解为跨sqlSession;缓存是以nameSpace为单位的,不同的nameSpace下的操作不影响)

LRU 最近最少使用

使用二级缓存容易出现脏读,建议避免使用二级缓存,在业务层使用可控制的缓存代替更好。

二级缓存可以跨namespance共享

不同步二级缓存。
在这里插入图片描述
门面模式:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值