首页 > 其他 > 详细

多表查询

时间:2020-04-13 21:02:10      阅读:59      评论:0      收藏:0      [点我收藏+]

1.双表查询

<select id="findAll" resultType="plan">
        select * from plan join dept on plan.dept_id=dept.id
        <where>
            <if test="null!=name and name!=‘‘">
                and plan.name like concat(%,#{name},%)
            </if>
        </where>
    </select>
    <resultMap type="Plan" id="plan">
        <id column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="amount" property="amount"/>
        <result column="manager" property="manager"/>
        <result column="content" property="content"/>
        <association property="dept" javaType="Dept">
            <id column="id" property="id"/>
            <result column="name" property="name"/>
        </association>
    </resultMap>

2.三表查询

<resultMap type="com.liujin.cms.domain.Students" id="students">
        <id column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="date" property="date"/>
        <collection property="types" ofType="com.liujin.cms.domain.Types">
            <id column="x_id" property="x_id"/>
            <result column="type" property="type"/>
        </collection>
    </resultMap>
    <select id="findAll" resultMap="students">
        select s.id id,s.name name,s.date date,t.x_id x_id,t.type type from students s join
        s_t on s.id=s_t.id join types t on s_t.x_id=t.x_id
        <where>
            <if test="null!=name and name!=‘‘">
                and name like concat(%,#{name},%)
            </if>
            <if test="null!=x_id and x_id">
                and x_id=#{x_id}
            </if>
        </where>
    </select>

大于小于号

<if test="null!=date1 and date1!=‘‘">
                and date &gt;=#{date1}
            </if>
            <if test="null!=date2 and date2!=‘‘">
                and date &lt;=#{date2}
            </if>

 

多表查询

原文:https://www.cnblogs.com/liujinqq7/p/12693754.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!