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方法
}