mybatis的where和if标签配合使用


where标签用于简化sql的书写,if标签用于判断。大概的使用如下

<select id="getCountByPageInfo" parameterType="com.dabai.mytwo.entity.PageInfo">
        select count(*)
        from forum
        <where>
            <if test="institutionid!=null">
                institution_id=#{institutionid}
            </if>
            <if test="userid!=null">
                and author_id=#{userid}
            </if>
        </where>
    </select>

其中pageInfo类如下

public class PageInfo implements Serializable {

    private static final long serialVersionUID = 1L;
    private Integer totalcount;
    private Integer currentpage;
    private Integer totalpage;
    private Integer pagesize;
    private Long institutionid;
    private Long forumid;
    private String userid;
    private String ids;
    private String code;
    //get  set方法
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM