mybatis学习

<mapper namespace="com.alex.myBatis2.dao.DeptDao">


<resultMap  id="MyDept" type="Dept">
    <id column="deptId" property="deptId"/>
    <result column="deptName" property="deptName"/>
    <result column="enable" property="enable"/>
    <result column="pid" property="pid"/>
    <collection property="emps" ofType="Emp">
            <id column="empid" property="id"/>
                    <result column="age" property="age"/>
        <result column="create_time" property="createTime"/>
                <result column="name" property="name"/>
    </collection>
</resultMap>


    <sql id="select">select * from dept</sql>


    <select id="selectAll" resultMap="MyDept">
        SELECT emp.empid,emp.age,emp.create_time,emp.`name`,dept.deptName,dept.pid,dept.`enable`,dept.deptId FROM emp INNER JOIN dept ON dept.deptId=emp.deptId where dept.deptId=1;
    </select>
<select id="list" resultType="dept" parameterType="dept">
        <include refid="select"/>
<where>
<if test="deptName!=null and deptName!=''">
    and deptName =#{deptName}
</if>
<if test="enable==1">
    and enable=#{enable}
</if>
</where>
</select>

    <select id="findByPid" parameterType="dept" resultType="dept">
<include refid="select"/>
<where>
<choose>
<when test="pid==1">
    pid=1</when>
<otherwise>pid=4 and enable=1
</otherwise>
</choose>
</where>
    </select>
    <select id="findByid" resultType="com.alex.myBatis2.entity.Dept">

<include refid="select"/> where deptId in <foreach collection="list" item="item" open="(" separator="," close=")">
#{item}
</foreach>
    </select>
    <select id="find" resultType="com.alex.myBatis2.entity.Dept">
SELECT deptId,deptName from dept

    </select>
</mapper>
  <resultMap id="myResult" type="Emp">
        <id column="empid" property="id"/>
        <result column="age" property="age"/>
        <result  column="create_time" property="createTime"/>
        <result column="name" property="name"/>
        <association property="dept" javaType="Dept">
            <id column="deptId" property="deptId"/>
            <result column="deptName" property="deptName"/>
            <result column="enable" property="enable"/>
            <result column="pid" property="pid"/>
        </association>
    </resultMap>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值