首页 > 其他分享 >Mybatis-Plus 自定义xml分页

Mybatis-Plus 自定义xml分页

时间:2022-10-14 11:26:31浏览次数:52  
标签:xml name 自定义 role IPage Mybatis query id

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>

标签:xml,name,自定义,role,IPage,Mybatis,query,id
From: https://www.cnblogs.com/marchxd/p/16791012.html

相关文章