进行快速创建IPage对象 page是分页的要求,wrapper是分页的搜查要求 -- 这里的Query是一个封装
IPage[span class="cm-variable">AppPregnancyEntityAppPregnancyEntity
public class Query[span class="cm-variable">T
?
public IPage[span class="cm-variable">TString, Object
return this.getPage(params, null, false);
}//代码效果参考:http://www.ezhiqi.com/bx/art_195.html
?
public IPage[span class="cm-variable">TString, Object
//分页参数
long curPage = 1;
long limit = 10;
?
if(params.get(Constant.PAGE) != null){
curPage = Long.parseLong((String)params.get(Constant.PAGE));
}
if(params.get(Constant.LIMIT) != null){
limit = Long.parseLong((String)params.get(Constant.LIMIT));
}
?
//分页对象
Page[span class="cm-variable">T
?
//分页参数
params.put(Constant.PAGE, page);
?
//排序字段
//防止SQL注入(因为sidx、order是通过拼接SQL实现排序的,会有SQL注入风险)
String orderField = SQLFilter.sqlInject((String)params.get(Constant.ORDER_FIELD));
String order = (String)params.get(Constant.ORDER);
?
?
//前端字段排序
if(StringUtils.isNotEmpty(orderField) StringUtils.isNotEmpty(order)){
if(Constant.ASC.equalsIgnoreCase(order)) {
return page.addOrder(OrderItem.asc(orderField));
}else {
return page.addOrder(OrderItem.desc(orderField));
}
}
?
//没有排序字段,则不排序
if(StringUtils.isBlank(defaultOrderField)){
return page;
}
?
//默认排序
if(isAsc) {
page.addOrder(OrderItem.asc(defaultOrderField));
}else {
page.addOrder(OrderItem.desc(defaultOrderField));
}
?
return page;
}
}
?
如何跑起来? -- 以AppTrouble为例子 QueryWrapper具体看Mybatis-plus
1.serviceImpl
// 进行分页查询
Page[span class="cm-variable">AppTroubleEntity
?
IPage[span class="cm-variable">AppTroubleEntity
2.appTroubleDao
@Mapper
@Repository
public interface AppTroubleDao extends BaseMapper[span class="cm-variable">AppTroubleEntity
?
/*
肇事记录页面查询
@param page
@param queryWrapper
@return
/
IPage[span class="cm-variable">AppTroubleEntityAppTroubleEntity
}//代码效果参考:http://www.ezhiqi.com/bx/art_769.html
3.appTroubleDao.xml
[span class="cm-tag">select id="selectAppTroubleMy" resultType="com.uht.modules.app.entity.AppTroubleEntity"
SELECT app_trouble.*,user_info.name as userName,sys_org.name AS communityStr
FROM app_trouble
INNER JOIN user_info ON app_trouble.user_id = user_info.id
INNER JOIN sys_org ON app_trouble.community = sys_org.id
${ew.customSqlSegment}
热水有益于身体健康