首页 > 代码库 > 多条件分页查找(SQL拼接方法)
多条件分页查找(SQL拼接方法)
def startTime=params.startTime+" 00:00:00"
def endTime=params.endTime + " 23:59:59"
def SQL ="from Timage where 1=1 "
params.max = 2
//设置偏移量
if (!params.offset) params.offset = 0
// params.offset=""
if(params.keyWord != ""){
SQL += " and comment like ‘%${params.keyWord}%‘"
}
if(params.author!= ""){
SQL = SQL + " and author like ‘%${params.author}%‘"
}
if(params.startTime!=""){
SQL += " and createtime >= ‘${startTime}‘"
}
if(params.endTime!=""){
SQL += " and publishtime <= ‘${endTime}‘"
}
def List = Timage.findAll(SQL,[max:params.max,offset:params.offset as int])
// def Lista = Timage.findAll(SQL)
render(view:"searchMuchList",model:[offset:params.offset,muchres: List, muchCount:Timage.count(),keyWord:params.keyWord,author:params.author,startTime:params.startTime,endTime:params.endTime])
-----------
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd")格式化为时间日期字符串
sdf.format转为StringBuffer类型
sdf.parse转换为date类型
多条件分页查找(SQL拼接方法)