1、控制器中的写法示例:
/**
* jfinal3.0+在SQL语句中使用if语句
*/
public void user_list() {
int pageNumber = getParaToInt("page",1);
int pageSize = getParaToInt("rows",10);
//登录人员账号
String username = getPara("username");
//登录人员昵称
String nickname = getPara("nickname");
if(StrKit.notBlank(nickname)) {
nickname = "%" + nickname + "%";
}
Kv cond = Kv.by("username", username)
.set("nickname", nickname);
SqlPara sqlPara = Db.getSqlPara("sys.user_list", cond);
Page<Record> pageRecord = Db.paginate(pageNumber, pageSize, sqlPara);
//下面的render语句是我自己封装的,以你们实际的为准喔 ^_^
this.renderDataGrid(pageRecord);
}
2、SQL语句中的写法示例:
#namespace("sys")
#sql("user_list")
select * from sys_user where 1=1
#if(username)
and username = #para(username)
#end
#if(nickname)
and nickname like #para(nickname)
#end
#end
#end