<?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="org.niugang.dept.dao.DeptDao">
<resultMap id="BaseResultMap"
type="org.niugang.dept.entity.DeptEntity">
<result column="c_id" property="id" />
<result column="c_dept_name" property="deptName" />
<result column="c_parent_id" property="parentId" />
<result column="c_code" property="code" />
<result column="c_delete_flag" property="deleteFlag" />
<result column="c_quanpin" property="quanPin" />
<result column="c_jianpin" property="jianPin" />
<result column="c_createtime" property="createTime" />
<result column="c_creator" property="creator" />
<result column="c_updatetime" property="updateTime" />
<result column="c_updator" property="updator" />
<result column="c_version" property="version" />
</resultMap>
<!--查询字段 -->
<sql id="Base_Column_List">
<choose>
<!--只查询给定字段 -->
<when test="queryField!=null">
<foreach collection="queryField" separator="," item="item">
<if test="item!=null and item!=''">
<!--这里只能用${},因为${}是指传什么就用什么,而#{}是根据传的调用起get..方法 -->
${item}
</if>
</foreach>
</when>
<!--查询全部字段 -->
<otherwise>
c_id,
c_dept_name,
c_parent_id,
c_code,
c_delete_flag,
c_quanpin,
c_jianpin,
c_createtime,
c_creator,
c_updatetime,
c_updator,
c_version
</otherwise>
</choose>
</sql>
<!-- 查询条件 -->
<sql id="queryCondition">
<where>
<if test="id!=null">
and c_id=#{id}
</if>
<if test="deptName!=null and deptName!=''">
and c_dept_name like "%"#{deptName}"%"
</if>
<if test="parentId!=null and parentId!=''">
and c_parent_id =#{parentId}
</if>
<if test="code!=null and code!=''">
and c_code like "%"#{code}"%"
</if>
<if test="deleteFlag!=null and deleteFlag!=''">
and c_delete_flag=#{deleteFlag}
</if>
<if test="quanPin!=null and quanPin!=''">
and c_quanpin like "%"#{quanPin}"%"
</if>
<if test="jianPin!=null and jianPin!=''">
and c_jianpin like "%"#{jianPin}"%"
</if>
<if test="createTime!=null and createTime!=''">
and c_createtime=#{createTime}
</if>
<if test="creator!=null and creator!=''">
and c_creator=#{creator}
</if>
<if test="updateTime!=null and updateTime!=''">
and c_updatetime=#{updateTime}
</if>
<if test="version!=null and version!=''">
and c_version=#{version}
</if>
</where>
</sql>
<!--分页查询条件 -->
<sql id="limitCoddition">
order by c_id desc limit
<choose>
<when test="startRecord!=null and startRecord!=''">
#{startRecord},
</when>
<otherwise>
0,
</otherwise>
</choose>
<choose>
<when test="pageSize!=null and pageSize!=''">
#{pageSize}
</when>
<otherwise>
10
</otherwise>
</choose>
</sql>
<!--查询集合 -->
<select id="getList" resultMap="BaseResultMap"
parameterType="org.niugang.dept.bean.DeptQueryBean">
select
<include refid="Base_Column_List" />
from t_boot_dept
<include refid="queryCondition" />
</select>
<!--分页查询 -->
<select id="getListByPage" resultMap="BaseResultMap"
parameterType="org.niugang.dept.bean.DeptQueryBean">
select
<include refid="Base_Column_List" />
from t_boot_dept
<include refid="queryCondition" />
<include refid="limitCoddition" />
</select>
<!--插入 -->
<insert id="insert"
parameterType="org.niugang.dept.bean.DeptQueryBean">
<!-- mysql数据库自增 -->
<selectKey resultType="java.lang.Integer" order="AFTER"
keyProperty="id" keyColumn="c_id">
SELECT LAST_INSERT_ID() AS id
</selectKey>
INSERT INTO `t_boot_dept` (
<trim suffixOverrides=",">
<!--字符串类型需要判断是否为'' -->
<!--对象只需要判断是否为空 -->
<if test="deptName!=null and deptName!=''">
`c_dept_name`,
</if>
<if test="parentId!=null">
`c_parent_id`,
</if>
<if test="code!=null and code!=''">
`code`,
</if>
<if test="deleteFlag!=null and deleteFlag!=''">
`c_delete_flag`,
</if>
<if test="quanPin!=null and quanPin!=''">
`c_quanpin`,
</if>
<if test="jianPin!=null and jianPin!=''">
`c_jianpin`,
</if>
`c_createtime`,
<if test="creator!=null and creator!=''">
`c_creator`,
</if>
<if test="updateTime!=null">
`c_updatetime`,
</if>
<if test="updator!=null and updator!=''">
`c_updator`,
</if>
<if test="version!=null">
`c_version`
</if>
</trim>
)
VALUES
(
<trim suffixOverrides=",">
<if test="deptName!=null and deptName!=''">
#{deptName},
</if>
<if test="parentId!=null">
#{parentId},
</if>
<if test="code!=null and code!=''">
#{code},
</if>
<if test="deleteFlag!=null and deleteFlag!=''">
#{deleteFlag},
</if>
<if test="quanPin!=null and quanPin!=''">
#{quanPin},
</if>
<if test="jianPin!=null and jianPin!=''">
#{jianPin},
</if>
NOW(),
<if test="creator!=null and creator!=''">
#{creator},
</if>
<if test="updateTime!=null">
#{updateTime},
</if>
<if test="updator!=null and updator!=''">
#{updator},
</if>
<if test="version!=null">
#{version}
</if>
</trim>
)
</insert>
<!--删除 -->
<delete id="delete" parameterType="int">
delete from t_boot_dept where
c_id =#{id}
</delete>
<!--根据主键查询 -->
<select id="getById" parameterType="int"
resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_boot_dept
where c_id =#{id}
</select>
<!--查询单个对象 -->
<select id="get"
parameterType="org.niugang.dept.bean.DeptQueryBean"
resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_boot_dept
<include refid="queryCondition" />
</select>
<!--查询数量 -->
<select id="count"
parameterType="org.niugang.dept.bean.DeptQueryBean" resultType="int">
select count(*) from t_boot_dept
<include refid="queryCondition" />
</select>
<!--更新 -->
<update id="update"
parameterType="org.niugang.dept.bean.DeptQueryBean">
<if test="id!=null">
update t_boot_dept
<trim prefix="set" suffixOverrides=",">
<if test="deptName!=null and deptName!=''">
c_dept_name=#{deptName},
</if>
<if test="parentId!=null and parentId!=''">
c_parent_id=#{parentId},
</if>
<if test="code!=null and code!=''">
c_code=#{code},
</if>
<if test="deleteFlag!=null and deleteFlag!=''">
c_delete_flag=#{deleteFlag},
</if>
<if test="quanPin!=null and quanPin!=''">
c_quanpin=#{quanPin},
</if>
<if test="jianPin!=null and jianPin!=''">
c_jianpin=#{jianPin},
</if>
<if test="createTime!=null">
c_createtime=#{createTime},
</if>
<if test="creator!=null and creator!=''">
c_creator=#{creator},
</if>
c_updatetime=now(),
<if test="version!=null and version!=''">
c_version=#{version}
</if>
</trim>
where c_id=#{id}
</if>
</update>
</mapper>