<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 最近最少使用
使用二级缓存容易出现脏读,建议避免使用二级缓存,在业务层使用可控制的缓存代替更好。