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