javaweb练习分析——4

对于单表的查询可能会有多种,其中较为简单的是查询所有、根据id查询、根据其他单一条件查询,但有时会遇到相较于前面的操作较为复杂的操作,就是多条件查询。
需要根据前端页面输入的条件来查询。
对比简单的查询操作第一个区别是用注解不在适用,要在mapper.xml文件中书写sql语句

<select id="selectByCondition1" resultType="com.wjh.pojo.House">
        select *
        from houseinfo
        <where>
            <if test="roomType!=null and roomType!='' ">
                and roomType = #{roomType}
            </if>

            <if test="address!=null and address!='' ">
                and address = #{address}
            </if>

            <if test="year!=null">
                and year > #{year}
            </if>

            <if test="area!=null">
                and area > #{area}
            </if>

            <if test="sales!=null">
                and sales > #{sales}
            </if>

            and status = '在售'

        </where>


    </select>

之后就跟前面的一样在service和servlet实现相应功能

posted @ 2024-12-21 21:08  Look_Back  阅读(7)  评论(0)    收藏  举报