40 lines
1.1 KiB
Java
40 lines
1.1 KiB
Java
|
|
package com.hongliang.videotask.MapperProvider;
|
||
|
|
|
||
|
|
import org.apache.ibatis.annotations.Param;
|
||
|
|
|
||
|
|
import java.util.Map;
|
||
|
|
|
||
|
|
public class NodeProvider {
|
||
|
|
/**
|
||
|
|
* 组合条件查询
|
||
|
|
* @param condition 包含pageNum,pageSize,查询字段项,orderby
|
||
|
|
* @return
|
||
|
|
*/
|
||
|
|
public String GetNodeList(Map<String,Object> condition){
|
||
|
|
// System.out.println("condition:"+condition.toString());
|
||
|
|
// 使用StringBuilder来拼接SQL
|
||
|
|
StringBuilder sb=new StringBuilder();
|
||
|
|
sb.append("select * from node where 1=1");
|
||
|
|
|
||
|
|
//开如拼接查询条件
|
||
|
|
if (condition.containsKey("nodename")){
|
||
|
|
sb.append(" and nodename like concat('%', #{nodename},'%')");
|
||
|
|
}
|
||
|
|
|
||
|
|
//……如果有其他条件,就继续
|
||
|
|
|
||
|
|
//如果有排序
|
||
|
|
if (condition.containsKey("orderby")){
|
||
|
|
sb.append(" order by #{orderby}");
|
||
|
|
}
|
||
|
|
|
||
|
|
//拼接分页
|
||
|
|
if (condition.containsKey("offset") && condition.containsKey("pageSize")){
|
||
|
|
sb.append(" limit #{offset},#{pageSize}");
|
||
|
|
}
|
||
|
|
|
||
|
|
//返回sql语句
|
||
|
|
return sb.toString();
|
||
|
|
}
|
||
|
|
}
|