加载中......

Mybatis-Plus 自定义xml分页

1.定义实体类

@TableName("role")
@Data
public class Role {
    @TableId
    private String id;
    private String name;
}

2.定义mapper接口

public interface RoleMapper extends BaseMapper<Role> {
	//xml分页
	IPage<Role> getRolePage(IPage<Role> page);
	
	//xml分页带条件
	IPage<Role> getRolePageByCondition(IPage<Role> page, @Param("query")Role query);
}

3.编写XML

<select id="getRolePage" resultType="com.hj.entity.Role">
    select * from role
</select>

<select id="getRolePageByCondition" resultType="com.hj.entity.Role">
    select * from role
    <where>
        <if test="query.id != '' and query.id != null">
            id = #{query.id}
        </if>
        <if test="query.name != '' and query.name != null">
            or name = #{query.name}
        </if>
    </where>
</select>
posted @ 2022-10-14 11:13  MarchXD  阅读(115)  评论(0编辑  收藏  举报