以下是教材的sql语句,我跟教材唯独表名不一样。教材也是resultMap,所以不要再说把reaultMap改为resultType了
<?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="com.mmall.dao.SysDeptMapper" >
<resultMap id="BaseResultMap" type="com.mmall.model.SysDept" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="parent_id" property="parentId" jdbcType="INTEGER" />
<result column="level" property="level" jdbcType="VARCHAR" />
<result column="seq" property="seq" jdbcType="INTEGER" />
<result column="remark" property="remark" jdbcType="VARCHAR" />
<result column="operator" property="operator" jdbcType="VARCHAR" />
<result column="operate_time" property="operateTime" jdbcType="TIMESTAMP" />
<result column="operate_ip" property="operateIp" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, name, parent_id, level, seq, remark, operator, operate_time, operate_ip
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from sys_dept
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from sys_dept
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.mmall.model.SysDept" >
insert into sys_dept (id, name, parent_id,
level, seq, remark,
operator, operate_time, operate_ip
)
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{parentId,jdbcType=INTEGER},
#{level,jdbcType=VARCHAR}, #{seq,jdbcType=INTEGER}, #{remark,jdbcType=VARCHAR},
#{operator,jdbcType=VARCHAR}, #{operateTime,jdbcType=TIMESTAMP}, #{operateIp,jdbcType=VARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="com.mmall.model.SysDept" keyProperty="id" useGeneratedKeys="true">
insert into sys_dept
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="name != null" >
name,
</if>
<if test="parentId != null" >
parent_id,
</if>
<if test="level != null" >
level,
</if>
<if test="seq != null" >
seq,
</if>
<if test="remark != null" >
remark,
</if>
<if test="operator != null" >
operator,
</if>
<if test="operateTime != null" >
operate_time,
</if>
<if test="operateIp != null" >
operate_ip,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="name != null" >
#{name,jdbcType=VARCHAR},
</if>
<if test="parentId != null" >
#{parentId,jdbcType=INTEGER},
</if>
<if test="level != null" >
#{level,jdbcType=VARCHAR},
</if>
<if test="seq != null" >
#{seq,jdbcType=INTEGER},
</if>
<if test="remark != null" >
#{remark,jdbcType=VARCHAR},
</if>
<if test="operator != null" >
#{operator,jdbcType=VARCHAR},
</if>
<if test="operateTime != null" >
#{operateTime,jdbcType=TIMESTAMP},
</if>
<if test="operateIp != null" >
#{operateIp,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.mmall.model.SysDept" >
update sys_dept
<set >
<if test="name != null" >
name = #{name,jdbcType=VARCHAR},
</if>
<if test="parentId != null" >
parent_id = #{parentId,jdbcType=INTEGER},
</if>
<if test="level != null" >
level = #{level,jdbcType=VARCHAR},
</if>
<if test="seq != null" >
seq = #{seq,jdbcType=INTEGER},
</if>
<if test="remark != null" >
remark = #{remark,jdbcType=VARCHAR},
</if>
<if test="operator != null" >
operator = #{operator,jdbcType=VARCHAR},
</if>
<if test="operateTime != null" >
operate_time = #{operateTime,jdbcType=TIMESTAMP},
</if>
<if test="operateIp != null" >
operate_ip = #{operateIp,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.mmall.model.SysDept" >
update sys_dept
set name = #{name,jdbcType=VARCHAR},
parent_id = #{parentId,jdbcType=INTEGER},
level = #{level,jdbcType=VARCHAR},
seq = #{seq,jdbcType=INTEGER},
remark = #{remark,jdbcType=VARCHAR},
operator = #{operator,jdbcType=VARCHAR},
operate_time = #{operateTime,jdbcType=TIMESTAMP},
operate_ip = #{operateIp,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="getAllDept" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from sys_dept
</select>
<select id="getChildDeptListByLevel" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from sys_dept
WHERE level like #{level} || '.%'
</select>
<update id="batchUpdateLevel" parameterType="map">
<foreach collection="sysDeptList" item="sysDept" separator=";">
UPDATE sys_dept
SET level = #{dept.level}
WHERE id = #{dept.id}
</foreach>
</update>
<select id="countByNameAndParentId" parameterType="map" resultType="int">
SELECT count(1)
FROM sys_dept
WHERE name = #{name}
<if test="parentId != null">
AND parent_id = #{parentId}
</if>
<if test="id != null">
AND id != #{id}
</if>
</select>
<select id="countByParentId" parameterType="int" resultType="int">
SELECT count(1)
FROM sys_dept
WHERE parent_id = #{deptId}
</select>
</mapper>